Summary: Troubleshooting CloudFormation Wait Conditions

When using AWS CloudFormation, you may encounter a scenario where a wait condition does not receive the required number of signals from an Amazon EC2 instance. This can be due to several reasons:

Steps to Debug CloudFormation Wait Condition Failures

  1. Disable Rollback on Failure
  2. Check Internet Connectivity
  3. Review Log Files
  4. Simulate Failure
  5. Observe Stack Creation
  6. Use Stack Failure Options

Example: CloudFormation Template Modification to Simulate Failure

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Metadata:
      AWS::CloudFormation::Init:
        config:
          commands:
            test_failure:
              command: "echo boom && exit 1"

In the above example, the echo boom && exit 1 command in the CloudFormation template will cause the cfn-init script to fail, which in turn will cause the cfn-signal to send a failure signal to the wait condition.

Conclusion

Understanding the use of cfn-signal and wait conditions is crucial for managing CloudFormation stacks. Properly configuring rollback settings and knowing how to access and debug EC2 instances can help identify issues during stack creation and development cycles.