Soru

Zorluk: OrtaAWS CloudFormation

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?

  1. A
    Manually 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.
  2. B
    Configure 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.
  3. 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.Cevap
  4. D
    Run 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.

Cevap

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.

Adım Adım Çözüm

1
Define the application metadata and configuration script on the EC2 resource using the AWS::CloudFormation::Init key.
The instance metadata contains the configuration details, which will be processed by cfn-init.
This allows CloudFormation to manage packages, files, and services systematically on the EC2 instance.
2
Add a CreationPolicy attribute with a ResourceSignal count of 1 and a timeout configuration to the EC2 resource.
CloudFormation is instructed to pause resource creation and wait for a success signal before marking the instance as CREATE_COMPLETE.
This prevents CloudFormation from prematurely finishing stack creation before the software is operational.
3
Execute the cfn-signal helper script at the very end of the instance's UserData property, immediately after invoking cfn-init.
A success signal is sent to the CloudFormation endpoint once all setup steps successfully run.
This signals CloudFormation that the instance setup is successful, causing the resource status to transition to CREATE_COMPLETE.

Anahtar Kavram

Using CreationPolicy and helper scripts (cfn-init, cfn-signal) to synchronize resource provisioning inside AWS CloudFormation.
Tahmini Süre:1m 30s
Bu soruyu puanla