当前位置: 首页 > 知识库问答 >
问题:

如何使用云形成模板将Fargate集群服务与任务定义集成/链接

严远
2023-03-14

我有以下的云形成模板片段。整个模板创建了ECS法门集群以及所有资源。但是现在,我面临着法门服务和任务定义的问题。

模板的服务部分如下所示:

服务:

    Type: AWS::ECS::Service

    # This dependency is needed so that the load balancer is setup correctly in time

    Properties:

      ServiceName: !Ref ServiceName

      Cluster: !Ref Cluster

      TaskDefinition: !Ref TaskDefinition

      DeploymentConfiguration:

        MinimumHealthyPercent: 100

        MaximumPercent: 200

      DesiredCount: 2

      # This may need to be adjusted if the container takes a while to start up

      HealthCheckGracePeriodSeconds: 30

      LaunchType: FARGATE

      NetworkConfiguration:

        AwsvpcConfiguration:

          # change to DISABLED if you're using private subnets that have access to a NAT gateway

          AssignPublicIp: ENABLED

          Subnets:

            - !Ref abcvmnSubnetA

            - !Ref abcvmnSubnetB

          SecurityGroups:

            - !Ref ContainerSecurityGroup

      LoadBalancers:

        - ContainerName: !Ref ServiceName

          ContainerPort: !Ref ContainerPort

          TargetGroupArn: !Ref TargetGroup

任务定义如下:

任务定义:

    Type: AWS::ECS::TaskDefinition

    # Makes sure the log group is created before it is used.

    DependsOn: LogGroup

    Properties:

      # Name of the task definition. Subsequent versions of the task definition are grouped together under this name.

      Family: abc-taskdef-dev

      # awsvpc is required for Fargate

      NetworkMode: awsvpc

      RequiresCompatibilities:

        - FARGATE


      Cpu: 512


      Memory: 1GB

      # A role needed by ECS.

      # "The ARN of the task execution role that containers in this task can assume. All containers in this task are granted the permissions that are specified in this role."

      # "There is an optional task execution IAM role that you can specify with Fargate to allow your Fargate tasks to make API calls to Amazon ECR."

      ExecutionRoleArn: arn:aws:iam::890543041640:role/ecsTaskExecutionRole

      # "The Amazon Resource Name (ARN) of an AWS Identity and Access Management (IAM) role that grants containers in the task permission to call AWS APIs on your behalf."

      TaskRoleArn: arn:aws:iam::890543041640:role/ecsTaskExecutionRole

      ContainerDefinitions:

        - Name: abc-sampleappcontainer-dev

          Image: 890543041640.dkr.ecr.eu-central-1.amazonaws.com/abc:latest

          PortMappings:

            - ContainerPort: 8080

          # Send logs to CloudWatch Logs

          LogConfiguration:

            LogDriver: awslogs

            Options:

              awslogs-region: eu-central-1

              awslogs-group: /ecs/abc-taskdef-dev

              awslogs-stream-prefix: ecs

我知道,fargate服务和任务定义在集群中是相互关联的。但问题是,如何使用模板建立这种关系。

我收到以下失败事件:

任务定义中不存在容器abc服务开发人员。(服务:AmazonECS;状态代码:400;错误代码:InvalidParameterException;请求ID:008417e7-126e-11e9-98cb-ef191beeddae)

不确定,我哪里做错了。

共有1个答案

翟源
2023-03-14

你的电话号码是154

        - Name: abc-sampleappcontainer-dev

改变为

        - Name: !Ref ServiceName

相反因为你在272号线上

        - ContainerName: !Ref ServiceName

两者需要匹配。下面是一个有效的示例:

请注意名称“jaeger query”

  QueryTaskDef:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - Command: !Ref 'AWS::NoValue'
          Name: jaeger-query
          Cpu: !Ref CpuReservation
          Essential: 'true'
          Image: !Ref QueryImageName
          Memory: !Ref MemoryReservation
          Environment:
            - Name: SPAN_STORAGE_TYPE
              Value: elasticsearch
            - Name: ES_SERVER_URLS
              Value: !Sub 'http://${EsHost}:9200/'
          PortMappings:
            - ContainerPort: 16686
            - ContainerPort: 16687
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref LxDockerLog
              awslogs-region: !Ref 'AWS::Region'
              awslogs-stream-prefix: !Ref 'AWS::StackName'
  QueryService:
    Type: 'AWS::ECS::Service'
    DependsOn: AlbListenerRule
    Properties:
      Cluster: !Ref EcsCluster
      Role: !Ref ServiceSchedulingRole
      LoadBalancers:
        - ContainerName: jaeger-query
          ContainerPort: 16686
          TargetGroupArn: !Ref AlbTargetGroup
      DesiredCount: 2
      TaskDefinition: !Ref QueryTaskDef
  AlbListenerRule:
    Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
    Properties:
      Actions:
        - Type: forward
          TargetGroupArn: !Ref AlbTargetGroup
      Conditions:
        - Field: host-header
          Values: [!Sub '${Subdomain}.${HostedZoneName}']
      ListenerArn: !Ref HttpListener
      Priority: !Ref ListenerPriority
  AlbTargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      HealthCheckIntervalSeconds: '60'
      HealthCheckPath: '/'
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: '30'
      HealthyThresholdCount: 10
      Port: 16686
      Protocol: HTTP
      UnhealthyThresholdCount: 10
      VpcId: !Ref VpcId
      TargetGroupAttributes:
        - Key: deregistration_delay.timeout_seconds
          Value: !Ref DeregistrationDelay
 类似资料:
  • 问题内容: 如何将CodeIgniter和WordPress集成在一起,以便将WordPress博客的外观/模板延续到CodeIgniter创建的页面上? 问题答案: 第一步是将CodeIgniter和WordPress文件移动到它们自己的目录中。 然后,将以下行放在CodeIgniter 文件的顶部。根据需要将路径更改为指向WordPress的根目录。 然后,您可以在视图内部使用以下功能: 其他

  • 我试图部署lambda函数和API网关。我用AWS CLI创建了一个. net核心web API项目。仅部署该函数并在aws Web控制台上手动创建API网关和资源确实有效。 如果我在模板中包含API网关,在通过web控制台或CLI部署SAM包后,我会收到以下错误: “未为方法定义集成(服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求

  • 10.9. 与特定应用服务器集成 一般来说,Spring的事务抽象与应用服务器是无关的。另外,使用Spring的JtaTransactionManager 类时,一种可选的方式是通过JNDI查询获得JTA UserTransaction 和 TransactionManager 对象,其中后者可以被设置为自动探测,这时针对不同的应用服务器有不同的方式。能够直接访问 TransactionManag

  • 该文档为服务端2.0接口文档,如果您第一次服务器端集成,我们强烈建议您直接使用服务端2.0接口,相较于服务端1.0的接口,服务端2.0接口上传数据更加稳定,并且提供了更丰富的接口。如设备信息、环境信息等。 对于无法在App客户端中布点的情况,您可以通过本文提供的接口,在应用服务器端或合适的位置时机上传用户及事件数据。 1. 接口地址 https://u.zhugeapi.com/open/v2/e

  • 在 Node.js 服务器中使用时相当简单直接,例如Express: npm install express --save const Vue = require('vue') const server = require('express')() const renderer = require('vue-server-renderer').createRenderer() server.g

  • 我正在开发一个使用密钥库的应用程序。这个应用程序是用。NET Core3.1(ASP.NET)编写的,这个应用程序从我的本地机器上运行得非常好。我将该应用程序部署为azure应用程序服务,现在得到“HTTP Error 500.30-ANCM In-Process Start failure”错误消息。我检查了应用程序事件日志,它说: “用户、组或应用程序'appId={appId};oid={o