How can this be achieved in a reliable and efficient way?
Write a script to continue backing up the RDS instance every five minutes.
Create an AWS Lambda function to take a snapshot of the RDS instance, and manually invoke the function before deleting the stack.
Use the Snapshot Deletion Policy in the CloudFormation template definition of the RDS instance.
Create a new CloudFormation template to perform backups of the RDS instance, and run this template before deleting the stack.
Explanations:
Continuously backing up the RDS instance every five minutes via a script is not a reliable solution for retaining data after stack deletion. It introduces complexity and manual effort, and it doesn’t integrate directly with CloudFormation’s resource management capabilities.
While creating an AWS Lambda function to manually take a snapshot before deleting the stack may work, this approach requires manual intervention and does not automate the retention process through CloudFormation itself.
The Snapshot Deletion Policy in the CloudFormation template ensures that snapshots of the RDS instance are preserved even after the stack is deleted. This is the most efficient and automated solution for retaining RDS data after stack deletion.
Creating a new CloudFormation template specifically for backups adds unnecessary complexity. Backups can be managed more efficiently by using the Snapshot Deletion Policy in the original template.