Achieving Database Snapshot Creation on Cloudformation Stack Deletion

Automated Database Snapshot Creation on Cloudformation Stack Deletion

Prev Question Next Question

Question

You are in charge of designing Cloudformation templates for your company.

One of the key requirements is to ensure that if a Cloudformation stack is deleted, a snapshot of the relational database is created which is part of the stack.

How can you achieve this in the best possible way?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - C.

The AWS documentation mentions the following.

With the DeletionPolicy attribute, you can preserve or (in some cases) backup a resource when its stack is deleted.

You specify a DeletionPolicy attribute for each resource that you want to control.

If a resource has no DeletionPolicy attribute, AWS CloudFormation deletes the resource by default.

Note that this capability also applies to update operations that lead to resources being removed.

For more information on the Deletion policy, please visit the below URL:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html

The best way to achieve the requirement of creating a snapshot of the relational database when a CloudFormation stack is deleted is by using the Deletion policy of the CloudFormation template. Therefore, the correct answer is C.

Explanation: CloudFormation is a service that enables users to model and provision AWS resources using templates. CloudFormation templates can define the resources that need to be provisioned or updated, as well as how to configure them. CloudFormation templates also provide options to control the behavior of resources when a stack is deleted.

In this scenario, the requirement is to create a snapshot of the relational database when a CloudFormation stack is deleted. Therefore, the best approach is to use the Deletion policy of the CloudFormation template. The Deletion policy defines the behavior of a resource when its stack is deleted.

AWS provides two Deletion policies for resources, Retain and Snapshot. The Retain policy prevents the resource from being deleted, while the Snapshot policy creates a snapshot of the resource before it is deleted.

To use the Snapshot policy in a CloudFormation template, the resource should have the DeletionPolicy attribute set to Snapshot. The following is an example of a CloudFormation template that creates an RDS instance and sets the DeletionPolicy to Snapshot:

yaml
Resources: MyDB: Type: AWS::RDS::DBInstance Properties: DBInstanceIdentifier: mydb Engine: mysql # Other properties DeletionPolicy: Snapshot

With this DeletionPolicy configuration, when the CloudFormation stack is deleted, the RDS instance will be deleted, and a snapshot of the RDS instance will be created before deletion.

Therefore, option C is the correct answer, and it is the best approach to achieve the requirement of creating a snapshot of the relational database when a CloudFormation stack is deleted.