amazon-web-services - 在您的集群中未找到任何容器实例

标签 amazon-web-services amazon-ecs

服务 cc-ui-service 无法放置任务,因为没有容器实例满足其所有要求。原因:在您的集群中找不到容器实例。

最佳答案

我也遇到了这个错误,从一开始就没有集群。所以也许您可以使用我的努力(使用 Fargate 完成,但其中一些也适用于 ec2)。

Parameters:

  Image:
    Description: The docker image
    Type: String
    Default: f00b4r

  ImageVersion:
    Description: The docker image version
    Type: String
    Default: "1.0.42"

  LogGroupName:
    Description: The CloudWatch log group
    Type: String
    Default: f00b4r-logs

Resources:

  AvTestCluster:
    Type: AWS::ECS::Cluster
    Properties: 
      ClusterName: NewCluster

  ServiceTaskRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "${AWS::StackName}-TaskRole"
      Path: "/"
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ecs-tasks.amazonaws.com
            Action:
              - sts:AssumeRole
      Policies:
        - PolicyName: !Sub "${AWS::StackName}-TaskRolePolicy"
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - s3:*
                  - dynamodb:*
                Resource: "*" # TODO: Set to least privilege

  ExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: ExecutionRoleFargate
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
            Action: 'sts:AssumeRole'
      ManagedPolicyArns:
        - 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'

  ServiceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: vpc-02d42422a429042
      GroupDescription: Access to the ECS Service
      SecurityGroupIngress:
        - CidrIp: 42.42.42.42/16
          IpProtocol: -1

  EcsService:
    Type: AWS::ECS::Service
    Properties:
      Cluster: !Ref 'TestCluster'
      DesiredCount: '1'
      LaunchType: FARGATE
      DeploymentConfiguration:
        MaximumPercent: 100
        MinimumHealthyPercent: 0
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: DISABLED
          SecurityGroups:
            - !Ref ServiceSecurityGroup
          Subnets: 
            - subnet-0345b4296042a84
            - subnet-02f3452b9c142de

      TaskDefinition: !Ref 'TaskDefinition'

  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Family: new-latest
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      Cpu: 256
      Memory: 0.5GB
      ExecutionRoleArn: !Ref ExecutionRole
      TaskRoleArn: !GetAtt ServiceTaskRole.Arn
      ContainerDefinitions:
        - Name: new-latest
          Essential: true
          Image:
            Fn::Join:
              - ""
              - - "84272424226"
                - ".dkr.ecr.eu-west-1.amazonaws.com/"
                - !Ref Image
                - ":"
                - !Ref ImageVersion
          LogConfiguration:
              LogDriver: awslogs
              Options:
                awslogs-group:
                  !Ref LogGroupName
                awslogs-region: !Ref AWS::Region
                awslogs-stream-prefix: new-latest
          Memory: 128         
          Command: ["sh", "-c", !Join [ "", [ "echo HelloFromFargate" ] ] ]

  RestoreUptimeQuotationDDBECSRole:
   Type: AWS::IAM::Role
   Properties:
     AssumeRolePolicyDocument:
       Version: 2012-10-17
       Statement:
         - Effect: Allow
           Principal:
             Service:
               - events.amazonaws.com
           Action:
             - sts:AssumeRole
     Path: /
     Policies:
       - PolicyName: NewPolicy
         PolicyDocument:
           Version: 2012-10-17
           Statement:
             - Effect: Allow
               Action: 'ecs:RunTask'
               Resource: !Ref TaskDefinition

  LogGroup:
    Type: "AWS::Logs::LogGroup"
    Properties:
      RetentionInDays: 30
      LogGroupName:
        !Ref LogGroupName

关于amazon-web-services - 在您的集群中未找到任何容器实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54726656/

相关文章:

amazon-web-services - 我可以计量或设置 s3 文件夹的大小限制吗

javascript - XMLHttpRequest - AWS API Gateway 请求的资源上不存在 'Access-Control-Allow-Origin' header

java - 如何使用 RunInstancesRequest 指定创建 AWS EC2 实例的实例类型

amazon-web-services - Kubernetes 中的 NGINX 无法解析 DNS

amazon-web-services - 通过 cloudformation 为 fargate launchtype 任务为 cloudwatch 事件规则创建 'Target'

node.js - 文件不会从 Amazon S3 中删除

aws-cli - AWS CLI 返回未知选项 : awsvpcConfiguration

amazon-web-services - Docker 在 AWS ECS 中创建许多容器

amazon-web-services - AWS ECS 服务任务被替换(原因请求超时)

amazon-web-services - 为什么任务定义没有被删除?