2
votes

In my template, I'm provisioning an ASG that uses an EC2 Launch template

In the UserData section, I do a cfn-init to provision the instance, which works fine.

However when I do the cfn-signal command, the command is successful (exit code of 0), but the Cloudformation stack never receives it, and the stack creation/update fails with Failed to receive 1 resource signal(s) for the current batch. Each resource signal timeout is counted as a FAILURE.

When I check Cloudtrail, I see that the SignalResource API call was completed, signaling the correct Stack and resource with a SUCCESS, (but a responseElements of null)

Excerpt from my Cloudformation template:

Resources:
  MyLaunchTemplate:
      Type: AWS::EC2::LaunchTemplate
      Metadata:
        'AWS::CloudFormation::Init':
          configSets:
            # lots-o-stuff to be done by cfn-init
      Properties:
        LaunchTemplateData:
          # Remove other attributes for brevity
          UserData:
            Fn::Base64:
              !Sub |
                #!/bin/bash -x
                yum update -y
                # gather ENI
                /opt/aws/bin/cfn-init -c install \
                  --stack ${AWS::StackName} \
                  --resource MyLaunchTemplate \
                  --region ${AWS::Region}
                /opt/aws/bin/cfn-signal -e $? \
                  --stack ${AWS::StackName} \
                  --resource MyAsg \
                  --region ${AWS::Region}
                echo $?
        LaunchTemplateName: my-launch-template
  MyAsg:
    Type: AWS::AutoScaling::AutoScalingGroup
      CreationPolicy:
        AutoScalingCreationPolicy:
          MinSuccessfulInstancesPercent: 100
        ResourceSignal:
          Count: 1
          Timeout: PT10M
      UpdatePolicy:
        AutoScalingReplacingUpdate:
          WillReplace: true
      Properties:
        # Remove other attributes for brevity
        LaunchTemplate:
          LaunchTemplateId: !Ref MyLaunchTemplate
          Version: !GetAtt MyLaunchTemplate.LatestVersionNumber

Any idea what I'm missing here?

2

2 Answers

1
votes

I had also faced a similar issue recently. It seems like cfn-signals don’t work with launch template for some reason. For test purposes I changed my launch template to a launch configuration and the cfn signal worked totally fine. It’s weird why AWS don’t support launch templates.

0
votes

It appears that the Amazon Linux AMI version is not the latest and cfn-signal script isn't installed on the instance. Bootstrap the EC2 instance using aws-cfn-bootstrap package.

Add yum install -y aws-cfn-bootstrap in UserData section.

Another possible cause could be that the value of the Timeout property for the CreationPolicy attribute is too low. Make sure that the value is high enough for tasks to run before the cfn-signal script sends signals to AWS CloudFormation resources.

If it still doesn't work, then do check out AWS Troubleshooting Guide for this issue.