A developer is configuring an AWS CloudFormation template to deploy an application consisting of an Amazon RDS database and an Auto Scaling Group of EC2 instances. They want to ensure that the database is fully provisioned and ready to accept connections before the EC2 instances, which depend on the database, are launched. How can this dependency be expressed in the CloudFormation template?
- AImplement a custom resource that waits for the RDS database to be ready.
- BUse the `DeletionPolicy` attribute on the RDS resource.
- CSet the `DependsOn` attribute of the Auto Scaling Group to the RDS database resource.
- DOrder the resources in the CloudFormation template with RDS first, then Auto Scaling Group.
Show answer & explanationAnswer & explanation
Correct answer: C. Set the `DependsOn` attribute of the Auto Scaling Group to the RDS database resource.
The `DependsOn` attribute in CloudFormation explicitly defines a dependency between resources. By setting the Auto Scaling Group's `DependsOn` attribute to the RDS database resource, CloudFormation ensures that the RDS database is successfully created before it attempts to create the Auto Scaling Group, thus meeting the requirement.
Why the other options are wrong
- A. While a custom resource could achieve this, it's an overly complex solution for a problem that `DependsOn` handles natively and simply.
- B. `DeletionPolicy` controls what happens to a resource when the stack is deleted, not its creation order or dependency.
- D. The physical order of resources in a CloudFormation template does not dictate their creation order. CloudFormation determines the creation order based on implicit and explicit dependencies.
CloudFormation DependsOn
An AWS CloudFormation resource attribute that explicitly specifies that a resource must be created, updated, or deleted only after another specified resource has reached a certain state, ensuring correct deployment order for dependent resources.
- Explicitly defines resource dependency.
- Ensures creation order.
- Prevents deployment failures due to missing dependencies.
Memory trick: DEPENDS-ON: Don't Ever Push, Every New Deployment, So Only Now.