Question

Difficulty: MediumAWS CloudFormation

A developer is writing an AWS CloudFormation template to deploy an Amazon EC2 instance that runs a web server. The developer wants to ensure that the EC2 instance is not marked as CREATE_COMPLETE until the web server application package is successfully installed and the service is started. If the installation fails or does not complete within 15 minutes, the stack creation should fail and rollback. Which TWO actions must the developer perform in the CloudFormation template and instance configuration to meet these requirements?

  1. Add a CreationPolicy attribute to the EC2 instance resource in the template and set the timeout property to 15 minutes.Answer
  2. B
    Add an UpdatePolicy attribute to the EC2 instance resource in the template to define the wait time for the initial creation signals.
  3. Execute the cfn-signal helper script in the instance's UserData after the installation and startup commands succeed.Answer
  4. D
    Run the cfn-hup daemon inside UserData to monitor the installation logs and automatically trigger stack rollback on failure.
  5. E
    Retrieve a signal token by referencing a Systems Manager parameter using a Secrets Manager dynamic reference format in the UserData.

Answer

To meet the requirements, the developer must add a CreationPolicy attribute to the EC2 instance resource with a timeout of 15 minutes, and execute the cfn-signal helper script in the instance's UserData after the installation and startup commands succeed.
The correct actions are adding a CreationPolicy attribute to the EC2 instance resource in the template and executing the cfn-signal helper script in the instance's UserData. The CreationPolicy tells CloudFormation to wait for a signal before marking the instance as successfully created, and the cfn-signal script transmits that signal from the EC2 instance after setup steps finish.

Step-by-Step Solution

1
Identify the mechanism CloudFormation uses to pause stack creation for resource initialization.
The CreationPolicy attribute is used to block resource completion until a success signal is received.
This prevents the EC2 instance from transitioning to CREATE_COMPLETE immediately after VM provisioning.
2
Determine the tool used inside the EC2 instance to send the initialization status to CloudFormation.
The cfn-signal helper script is executed at the end of the bootstrap script (UserData).
This sends the success or failure signal back to AWS CloudFormation, satisfying the CreationPolicy wait condition.

Key Concept

AWS CloudFormation CreationPolicy and Helper Scripts
Estimated Time:2m 0s
Rate this question