A developer is writing an AWS CloudFormation template to deploy an Amazon EC2 instance that runs a web application. The developer uses the AWS::CloudFormation::Init metadata key to install several software packages and configure application files during startup. However, when deploying the stack, CloudFormation marks the EC2 instance status as CREATE_COMPLETE immediately after the instance is provisioned, but before the software installation and configuration tasks have finished running. Which configuration should the developer implement to ensure the stack creation waits until the software setup on the instance is fully complete?
- AManually log into the EC2 instance via SSH to run the software installation scripts, and then use the AWS Management Console to update the stack parameters to force a manual synchronization.
- BConfigure the EC2 instance's UserData to write a completion status to AWS Secrets Manager, and use an AWS Systems Manager Parameter Store dynamic reference in the EC2 instance properties to poll for this secret during stack creation.
- Add a CreationPolicy attribute to the EC2 instance resource in the template, and execute the cfn-signal helper script at the end of the UserData property after the cfn-init execution.Answer
- DRun a script that detects if the stack enters the ROLLBACK_IN_PROGRESS state, and execute the cfn-signal script locally from the developer's command line to override the rollback process and force the stack to CREATE_COMPLETE.
Answer
Add a CreationPolicy attribute to the EC2 instance resource in the template, and execute the cfn-signal helper script at the end of the UserData property after the cfn-init execution.
The correct configuration is to add a CreationPolicy attribute to the EC2 instance resource and call the cfn-signal script at the end of UserData. This instructs CloudFormation to pause the status of the resource in CREATE_IN_PROGRESS until it receives the required number of signals or the timeout duration is reached.
Step-by-Step Solution
Key Concept
Using CreationPolicy and helper scripts (cfn-init, cfn-signal) to synchronize resource provisioning inside AWS CloudFormation.
Estimated Time:1m 30s