收到1个接收到的0个SUCCESS信号。无法满足100%MinSuccessfulInstancesPercent要求

时间:2019-08-03 08:29:39

标签: amazon-web-services amazon-cloudformation autoscaling

嗨,我正在研究云形成模板。我的目标是创建自动缩放组。下面是我的模板。

AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  AvailabilityZone:
    Default: "ap-southeast-2a"
    Type: "String"


Resources:
  MySecuritygroupLB:
    Type: AWS::EC2::SecurityGroup
    Properties:
       GroupDescription: "My security Group"
       GroupName: "MySecuritygroupLB"
       SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0

  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: 'LoadBalancer'
      SecurityGroups:
        - !GetAtt MySecuritygroupLB.GroupId
      Subnets:
        - subnet-b0ada9f9
        - subnet-9c7c76fb


  DefaultTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
       Name: 'DefaultTargetGroup'
       VpcId: 'vpc-d45072b3'
       Port: 80
       Protocol: HTTP
       TargetType: 'instance'
       Targets:
        - Id: !Ref FirstLinuxEC2instance

  LoadBalancerListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      LoadBalancerArn: !Ref LoadBalancer
      Port: 80
      Protocol: HTTP
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref DefaultTargetGroup

  MyAutoScallingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
       AutoScalingGroupName: MyAutoScallingGroup
       LaunchConfigurationName: !Ref LaunchConfig
       MaxSize: 3
       MinSize: 1
       TargetGroupARNs:
         - !Ref DefaultTargetGroup
       VPCZoneIdentifier:
         - subnet-b0ada9f9
         - subnet-9c7c76fb
    UpdatePolicy:
      AutoScalingRollingUpdate:
        MinInstancesInService: 1
        MaxBatchSize: 1
        PauseTime: PT15M
        WaitOnResourceSignals: True
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
        Count: 1

  LaunchConfig:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      KeyName: 'MyNewKeyPair'
      ImageId: 'ami-064fb5ae4f772d460'
      SecurityGroups:
        - !Ref MySecuritygroupLB
      InstanceType: 't2.micro'
      LaunchConfigurationName: LaunchConfig

  FirstLinuxEC2instance:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: !Ref AvailabilityZone
      ImageId: 'ami-0c1d8842b9bfc767c'
      InstanceInitiatedShutdownBehavior: 'terminate'
      InstanceType: 't2.micro'
      SecurityGroupIds:
        - !Ref MySecuritygroupLB
      KeyName: 'MyNewKeyPair'
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          sudo yum update -y
          sudo yum install httpd -y
          sudo chmod 777 /var/www/html/ -R
          sudo service httpd start
          cat <<'EOF' >> /var/www/html/index.html
          <!DOCTYPE html>
          <html>
          <head>
          <title>Garrett's Webpage</title>
          </head>
          <body>

          <h1>Welcome to Garrett's Sweet Webpage</h1>
          <p>This is a paragraph.</p>
          </body>
          </html>
          EOF

上面的模板工作正常,如果我删除启动配置和自动缩放组,则肯定是启动配置或自动缩放组出现问题。我创建了示例AMI,并且正在引用模板中的ID。我遇到错误

  

在1个信号中收到0个SUCCESS信号。无法满足100%   MinSuccessfulInstancesPercent要求

有人可以帮助我解决问题。任何帮助,将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

您需要将此添加到您的ec2用户数据中:

cfn-init -v --stack $ {AWS :: StackName} --resource AutoScalingGroup --region $ {AWS :: Region} cfn-signal -e 0 --stack $ {AWS :: StackName} --resource AutoScalingGroup --region $ {AWS :: Region}