Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't a Retain DeletionPolicy in CloudFormation preserve a changed DynamoDB table?

I'm using CloudFormation to construct an AWS::DynamoDB::Table resource, and I have my DeletionPolicy set to Retain. Suppose I make a change to the AttributeDefinitions properties of this logical resource, such as renaming a hash key, and then perform a CloudFormation update_stack; such a change requires a 'replacement' of the resource. So far so good; I expect that the existing DynamoDB table is 'deleted' and a new one created in its place with the changed key definition.

However, I'm surprised that the original table is not 'left behind' as a result of the DeletionPolicy. Certainly, it would be possible to block the update entirely via a stack policy, but I was hoping that the DeletionPolicy would result in the now-defunct table being ejected from the CloudFormation stack and a new one arising in its place, but nonetheless not actually deleted.

Is this expected behaviour?

like image 780
dliggat Avatar asked Jul 06 '16 23:07

dliggat


People also ask

What is true about DeletionPolicy in CloudFormation?

DeletionPolicy options. CloudFormation deletes the resource and all its content if applicable during stack deletion. You can add this deletion policy to any resource type. By default, if you don't specify a DeletionPolicy , CloudFormation deletes your resources.

What is not captured in the cloud formation template?

Using the NoEcho attribute does not mask any information stored in the following: The Metadata template section. CloudFormation does not transform, modify, or redact any information you include in the Metadata section.

When using DynamoDB do you need to replicate data for durability and backup?

DynamoDB achieves a high degree of data availability and durability by replicating your data across three different facilities within a given region. However, DynamoDB does not provide an SLA for the data durability. This means that you should backup your database tables.


2 Answers

Yes, it is an expected behavior.

The DeletionPolicy is only applied when you actually delete the whole CloudFormation stack.

Source: DeletionPolicy @ docs.aws.amazon.com

If you want to keep your former DynamoDB tables during an update, you will need to back it up manually beforehand. You may use AWS Data Pipeline to backup your DynamoDB tables on Amazon S3.

like image 154
Jon Avatar answered Oct 25 '22 02:10

Jon


Use AWS attribute "UpdateReplacePolicy: Retain".

like image 32
MickH Avatar answered Oct 25 '22 02:10

MickH