首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的ecs cloudformation模板有问题吗?

我的ecs cloudformation模板有问题吗?
EN

Stack Overflow用户
提问于 2020-06-05 05:27:15
回答 1查看 240关注 0票数 1

帮助我找不出我的ecs cloudformation堆栈出了什么问题下面是错误和我的代码。我完全不知所措,我一直收到错误“接收到0个成功信号(共1个)。无法满足100%的MinSuccessfulInstancesPercent要求”。谁能解释一下这个模板出了什么问题?

my errors from cloudformation

代码语言:javascript
复制
Description: >
  ECS Cluster configuration Template - CI & CD over AWS
Parameters:
  InstanceType:
    Type: String
    Default: t2.small

  ClusterSize:
    Type: Number
    Default: 2

  Subnets:
    Type: List<AWS::EC2::Subnet::Id>

  SourceSecurityGroup:
    Type: AWS::EC2::SecurityGroup::Id

  VpcId:
    Type: AWS::EC2::VPC::Id

  VpcDefaultSG:
    Type: String

  ECSAMI:
    Description: ECS-Optimized AMI ID
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id

Mappings:
  AWSRegionToAMI:
    eu-west-1:
      AMI: ami-bff32ccc
    ap-southeast-1:
      AMI: ami-c9b572aa
    ap-southeast-2:
      AMI: ami-48d38c2b
    eu-central-1:
      AMI: ami-bc5b48d0
    ap-northeast-2:
      AMI: ami-249b554a
    ap-northeast-1:
      AMI: ami-383c1956
    us-east-1:
      AMI: ami-60b6c60a
    sa-east-1:
      AMI: ami-6817af04
    us-west-1:
      AMI: ami-d5ea86b5
    us-west-2:
      AMI: ami-f0091d91

Resources:
  ECSRole:
    Type: AWS::IAM::Role
    Properties:
      Path: /
      RoleName: !Sub ecs-${AWS::StackName}
      AssumeRolePolicyDocument: |
        {
            "Statement": [{
                "Effect": "Allow",
                "Principal": { "Service": [ "ec2.amazonaws.com" ]},
                "Action": [ "sts:AssumeRole" ]
            }]
        }
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role

  InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: /
      Roles:
        - !Ref ECSRole

  SecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: !Sub ${AWS::StackName}-SG-ECS-hosts
      SecurityGroupIngress:
        - SourceSecurityGroupId: !Ref SourceSecurityGroup
          IpProtocol: -1 #-1 value to allow all traffic in the security group
      VpcId: !Ref VpcId

  Cluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: !Ref AWS::StackName

  AutoScalingGroup:
    DependsOn: Cluster
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      VPCZoneIdentifier: !Ref Subnets
      LaunchConfigurationName: !Ref LaunchConfiguration
      MinSize: 2
      MaxSize: 6
      DesiredCapacity: 2
      Tags:
        - Key: Name
          Value: !Sub ${AWS::StackName} - ECS Host
          PropagateAtLaunch: true #specify that the new tag will be applied to instances launched after the tag is created
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
    UpdatePolicy:
      AutoScalingRollingUpdate:
        MinInstancesInService: 1
        MaxBatchSize: 1
        PauseTime: PT15M
        SuspendProcesses:
          - HealthCheck
          - ReplaceUnhealthy
          - AZRebalance
          - AlarmNotification
          - ScheduledActions
        WaitOnResourceSignals: true

  LaunchConfiguration:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !Ref ECSAMI
      InstanceType: !Ref InstanceType
      IamInstanceProfile: !Ref InstanceProfile
      KeyName: cicdoverawsKeyPair
      SecurityGroups:
        - !Ref SecurityGroup
        - !Ref VpcDefaultSG
      UserData:
        "Fn::Base64": !Sub |
          #!/bin/bash
          yum install -y aws-cfn-bootstrap
          /opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration
          /opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration
    Metadata:
      AWS::CloudFormation::Init:
        configSets:
          InstallAndRun:
            - Install
            - Configure
        Install:
          packages:
            yum:
              git: []
              docker: []
          files:
            /etc/cfn/cfn-hup.conf:
              mode: 000400
              owner: root
              group: root
              content: !Sub |
                [main]
                stack=${AWS::StackId}
                region=${AWS::Region}
                interval=6
            /etc/cfn/hooks.d/cfn-auto-reloader.conf:
              content: !Sub |
                [cfn-auto-reloader-hook]
                triggers=post.update
                path=Resources.LaunchConfiguration.Metadata.AWS::CloudFormation::Init
                action=/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup --configsets InstallAndRun
                    services: #service key define which services should be enabled or disabled when the instance is launched
          services: #service key define which services should be enabled or disabled when the instance is launched
            sysvinit: # the key above is uspported by sysvinit
              cfn-hup:
                enabled: true
                ensureRunning: true
                files: # we want the cfn-hub to use the configuration files from below
                  - /etc/cfn/cfn-hup.conf
                  - /etc/cfn/hooks.d/cfn-auto-reloader.conf
        Configure:
          commands:
            01_add_instance_to_cluster:
              command: !Sub echo ECS_CLUSTER=${Cluster} > /etc/ecs/ecs.config
    CreationPolicy:
      ResourceSignal:
        Timeout: PT5M
Outputs:
  ClusterName:
    Description: ECS cluster Name
    Value: !Ref Cluster
EN

回答 1

Stack Overflow用户

发布于 2020-06-05 05:32:01

ASG 中的cfn-signal应该通知ASG,而不是启动配置。

因此,您可以更改为cfn-signal

代码语言:javascript
复制
 --resource LaunchConfiguration

转到

代码语言:javascript
复制
 --resource AutoScalingGroup

假设模板的其他一切都没问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62204398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档