首页 > 解决方案 > CloudFormation 模板在创建 ECS 服务时卡在 CREATE_IN_PROGRESS

问题描述

我正在 CloudFormation 中创建 ECS 服务。

logical ID = Service我没有收到任何错误,它只会位于阶段的 CREATE_IN_PROGRESS 处。

这是我的 CF 模板(ECS 集群和上面的一些其他内容,但由于相关性而被删除)。

  TaskDefinition:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      Family: flink
      Memory: 2048
      Cpu: 512
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE 
      ContainerDefinitions:
        - Name: flink-jobmanager
          Image: ACCOUNT_ID.dkr.ecr.us-west-1.amazonaws.com/teststack-flink:latest
          Essential: true
          PortMappings:
            - ContainerPort: 8081
              HostPort: 8081
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: ecs/flink-stream
              awslogs-region: !Ref AWS::Region
              awslogs-stream-prefix: ecs
          Command:
            - jobmanager
        - Name: flink-taskmanager
          Image: ACCOUNT_ID.dkr.ecr.us-west-1.amazonaws.com/teststack-flink:latest
          Essential: true
          Command:
            - taskmanager
      ExecutionRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole
      Volumes: []
      TaskRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole
      Tags:
        -
          Key: EnvironmentStage
          Value: !Ref EnvironmentStage

  Service:
    Type: 'AWS::ECS::Service'
    Properties:
      ServiceName: !Join ['', [!Ref EnvironmentStage, '-', !Ref 'AWS::StackName']]
      Cluster: !Join ['', ['arn:aws:ecs:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':cluster/', !Ref ECSCluster]]
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 75
      TaskDefinition: !Join ['', ['arn:aws:ecs:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':task-definition/', !Ref TaskDefinition]]
      # TaskDefinition: !Ref TaskDefinition
      DesiredCount: 1
      DeploymentController:
        Type: ECS
      EnableECSManagedTags: true
      PropagateTags: TASK_DEFINITION
      SchedulingStrategy: REPLICA
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups:
            - !Ref FlinkSecurityGroup
          Subnets:
            - subnet-466da11c
            - subnet-6fe65509
      Tags:
        -
          Key: EnvironmentStage
          Value: !Ref EnvironmentStage

当我手动设置容器时,它们都部署到集群中

标签: amazon-web-servicesamazon-cloudformationamazon-ecs

解决方案


检查后clusters -> CLUSTER_NAME -> tasks -> stopped我看到以下内容:

Status reason   CannotStartContainerError: Error response from daemon: 
failed to initialize logging driver: failed to create Cloudwatch log stream: 
ResourceNotFoundException: The specified log group does not exist.

问题只是我忘记在log group我的 CF 模板中添加 to 的创建。所以我添加了这个:

  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub ${EnvironmentStage}-service-flink

然后将LogConfigurationin修改TaskDefinition为:

LogConfiguration:
  LogDriver: awslogs
  Options:
    awslogs-group: !Ref LogGroup
    awslogs-region: !Ref 'AWS::Region'
    awslogs-stream-prefix: flink

现在 CF 模板就像一个魅力 :)


推荐阅读