AWS CloudFormation not creating initial instance i

2020-08-22 06:30发布

问题:

(Expired Pastbin Link Removed)

Then I try to create a stack is fails to create the Auto Scaling group as no EC2 instances are created. How do I trigger the creation of the initial instance?

Received 0 SUCCESS signal(s) out of 1. Unable to satisfy 100% MinSuccessfulInstancesPercent requirement

回答1:

I believe I was able to replicate your symptoms with your template - the issue may be related to the AMI you're using. I selected the AMI for my region from the marketplace link as referenced by the shortened url in the parameter description. I'm still waiting for resource creation to fail (been almost an hour!) but otherwise the symptoms match up.

While launching, the scaling group is visible in the ASG console but with 0 instances. However, the Activity History tab shows a number of attempts to launch an instance, and all fail:

The description on all of them is:

Description: Launching a new EC2 instance. Status Reason: In order to use this AWS Marketplace product you need to accept terms and subscribe. To do so please visit http://aws.amazon.com/marketplace/pp?sku=aw0evgkw8e5c1q413zgy5pjce. Launching EC2 instance failed.

Have you accepted the terms and subscribed to that AMI in the marketplace? There are more details here: https://aws.amazon.com/marketplace/help/200799470#topic1

Note: I believe you will only see the ASG in the console while cloudformation is waiting for it - after the cfn rolls back, the asg (and the activity history) will disappear. As I'm still waiting for the asg resource creation to fail, I haven't definitely confirmed this.



回答2:

Verify that the subnets where AutoScalingGroup's instances will be installed can connect to Internet using either a NAT gateway or Internet gateway. This because the instances install some packages from Internet in the UserData statement of the stack.



回答3:

Note - please see the other answer for the more likely culprit. Leaving this here as the missing configset may also cause problems once the first issue is resolved.

The UserData calls cfn-init which references a configset InstallAndRun that doesn't exist:

                    "/opt/aws/bin/cfn-init ",
                    "         --stack ", { "Ref" : "AWS::StackName" },
                    "         --resource LaunchConfig",
                    "         --configsets InstallAndRun ",
                    "         --region ", { "Ref" : "AWS::Region" },"\n",

To use cfn-init and specify a configset, you need to have specified a AWS::CloudFormation::Init block in the launch configuration metadata and include a configset definition referencing the config elements you wish cfn-init to execute. See http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html#aws-resource-init-configsets for more details.

As an example, you'd need:

"LaunchConfig" : {
  "Type" : "AWS::AutoScaling::LaunchConfiguration"    
  "Metadata" : {
    "AWS::CloudFormation::Init" : {
      "configSets" : {
        "InstallAndRun" : [ "config1" ]
      },
      "config1" : {
        "commands" : {
          "test" : {
            "command" : "echo \"$MAGIC\" > test.txt",
            "env" : { "MAGIC" : "I come from the environment!" },
            "cwd" : "~",
            "test" : "test ! -e ~/test.txt",
            "ignoreErrors" : "false"
          }
        }
      }
    }
  },
  "Properties" : {
     ...
  }
}

Without that Metadata, cfn-init will fail, and the cfn-signal line tell cloudformation that the resource initialisation has failed.

As a diagnostic process, try removing the reference to cfn-init and cfn-signal and seeing if the instance starts up. If it does, and you do have some instance configuration steps that you'd like to define using cfn-init, define the metadata block to specify the steps, and add the calls to cfn-init and cfn-signal back into the user data.



回答4:

I am sure someone might find this answer helpful. I had similar issue when I created Auto Scaling Group, I tried to debug the logs(cfn-init) where I could find nothing wrong. I had removed Creation Policy and Update Policy in the Auto Scaling Group as mentioned here https://serverfault.com/questions/1023697/received-0-success-signals-out-of-1-unable-to-satisfy-100-minsuccessfulinsta. Everything else like LB, Launch Config, Subnets, SGs were all creating successfully, however I was stuck on this particular issue for a while.