A developer is deploying a web application using AWS CloudFormation. The template configures an Amazon EC2 Auto Scaling group behind an Application Load Balancer. The EC2 instances must install application software packages and retrieve a database password from parameter storage during startup. The database password must be rotated automatically every 30 days. Currently, the stack deployment finishes and is marked complete before the application initialization script finishes on the EC2 instances, causing the application to fail to connect to the database. How should the developer configure the CloudFormation template and startup scripts to resolve these issues in a secure and reliable manner?
- AConfigure the launch template's UserData to run the initialization. If the configuration fails and the stack transitions to the ROLLBACK_IN_PROGRESS state, use the UpdateStack API with the ContinueUpdateRollback parameter to force the instances to retry the setup script without deleting the stack resources.
- BConfigure a CreationPolicy on the Auto Scaling group resource. Store the database password in AWS Systems Manager Parameter Store as a Standard Parameter to reduce costs, and use the ssm dynamic reference in the launch template's UserData to inject the password. Execute cfn-signal at the start of the UserData script before the application installation begins.
- Configure a CreationPolicy on the Auto Scaling group resource. Store the database password in AWS Secrets Manager to support automatic rotation, and configure the EC2 instances to retrieve the password at runtime using the AWS SDK. In the launch template's UserData script, execute the software installation, retrieve the database password, and invoke the cfn-signal helper script only after the initialization is fully complete.Cevap
- DManually log in to each EC2 instance after CloudFormation completes the stack deployment to install the software packages and configure the database connection. Run CloudFormation drift detection on the Auto Scaling group to ensure that the manual changes do not cause the stack to drift from its template definition.
Cevap
Configure a CreationPolicy on the Auto Scaling group resource. Store the database password in AWS Secrets Manager to support automatic rotation, and configure the EC2 instances to retrieve the password at runtime using the AWS SDK. In the launch template's UserData script, execute the software installation, retrieve the database password, and invoke the cfn-signal helper script only after the initialization is fully complete.
The correct solution uses a CreationPolicy on the Auto Scaling group resource to halt the stack creation progress until a success signal is received. By placing the cfn-signal command at the end of the UserData script, the developer ensures that the signal is only sent after the software packages are fully installed and configured. Furthermore, AWS Secrets Manager is used because it natively supports the required 30-day automatic rotation, and retrieving the secret at runtime using the AWS SDK is a secure practice.
Adım Adım Çözüm
Anahtar Kavram
CloudFormation CreationPolicy, helper scripts (cfn-signal), and Secrets Manager integration
Tahmini Süre:2m 30s