我的ecs cloudformation模板有问题吗?

问题描述 投票:0回答:1

求助 我搞不懂我的ecs cloudformation栈有什么问题,下面是错误和我的代码。我完全不明白,我一直收到错误信息 "Received 0 SUCCESS signal(s) out of 1. Unable to satisfy 100% MinSuccessfulInstancesPercent requirement"。谁能解释一下模板有什么问题?

我的错误来自于云表单

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
amazon-web-services amazon-ec2 amazon-cloudformation amazon-ecs
1个回答
1
投票

cfn-signal ...在你的ASG 应向助理秘书长发出信号而不是发射配置。

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

 --resource LaunchConfiguration

进入

 --resource AutoScalingGroup

假设其他一切与模板是好的。

© www.soinside.com 2019 - 2024. All rights reserved.