title: Cloudformation Stack not receiving signal from userdata in EC2 Launch Template
body: <p>In my template, I'm provisioning an ASG that uses an <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-launch-template.html" rel="nofollow noreferrer">EC2 Launch template</a></p>
  
  <p>In the <a href="https://docs.aws.amazon.com/en_pv/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata.html#cfn-ec2-launchtemplate-launchtemplatedata-userdata" rel="nofollow noreferrer"><code>UserData</code></a> section, I do a <a href="https://docs.aws.amazon.com/en_pv/AWSCloudFormation/latest/UserGuide/cfn-init.html" rel="nofollow noreferrer"><code>cfn-init</code></a> to provision the instance, which works fine.</p>
  
  <p>However when I do the <a href="https://docs.aws.amazon.com/en_pv/AWSCloudFormation/latest/UserGuide/cfn-signal.html" rel="nofollow noreferrer"><code>cfn-signal</code></a> command, the command is successful (exit code of 0), but the Cloudformation stack never receives it, and the stack creation/update fails with <code>Failed to receive 1 resource signal(s) for the current batch. Each resource signal timeout is counted as a FAILURE.</code></p>
  
  <p>When I check Cloudtrail, I see that the <code>SignalResource</code> API call was completed, signaling the correct Stack and resource with a <code>SUCCESS</code>, (but a <code>responseElements</code> of <code>null</code>)</p>
  
  <p>Excerpt from my Cloudformation template:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Any idea what I'm missing here?</p>