[Music]
hi I'm Sujit a cloud support engineer
here at the AWS office in Sydney
sometimes customers ask me how to delete
an AWS CloudFormation stack and retain
all or some of the resources provisioned
from the stack I tell them this is where
setting the deletion policy attribute
can help by default when you delete a
stack CloudFormation deletes all the
resources that it provisioned if you
need to modify this behavior you can set
a deletion policy attribute on your
resources and it's a good practice as
well
to date there are three values that can
be set for the deletion policy attribute
which is retain snapshot and delete
let's discuss these attributes further
retain if you have said deletion policy
to retain for a resource the resource
would continue to exist even after the
stack has been deleted snapshot setting
deletion policy to snapshot is supported
only for certain resources such as AWS
ec2 volume AWS RDS DB instance AWS RDS
DB cluster AWS redshift cluster AWS
elastic cache cache cluster AWS elastic
cache replication group
formation creates a snapshot of these
resources when you initiate a stack
digit the resources would be deleted at
the end of the stack delete operation
but the snapshot continues to exist
delete setting deletion policy to delete
is supported across all resource types
as you can see I am already logged into
my AWS console and about to initiate a
cloud formation stack creation so I
click on cloud formation
I have already downloaded the stacks to
my local system so I'm just about to
start with create new stack
click on browse
select a file which will open in finder
I'm clicking on one of the stacks
template which I have already downloaded
click on next
you are being prompted for the stag name
so I am about to set a stagnant as
deletion policy demo click on next
you are being prompted to enter a cloud
formation stack tag so I'm about to set
it name
and I'm setting the name as deletion
policy demo
click on next
as you can see the
has already been uploaded to an s3
bucket which cloud formation creates by
default
the description was pulled in from my
stack template
the stack name which I set at the
earliest part of the demo
the name
I click on create'
as you can see cloud form
has already kick-started the stack
it has moved in to create complete let's
check on the ec2 console
click on security groups within Network
and security
so my CloudFormation stack created two
security groups and assigned it deletion
policy demo
taking you back to the cloud formation
console
outputs these are the two security
groups that it created let's have a look
at the template
I'm just going to maximize the view here
as you can see my template just created
two security groups and I haven't set
decision policy anywhere
taking you back to the CloudFormation
console again after clicking on minimize
I'm about to delete the stack and the
expected behavior would be that cloud
formation would delete the two security
groups it created
clicking on refresh
there it's done I'm taking you back to
the ec2 management console
on refresh
so cloud formation has deleted both the
security groups
now if I wanted to retain the two
security groups that CloudFormation
created as you were I have guessed I
should update the template and set
decision policy to retain for both the
resources which I have already done and
modified on a sample template at my end
and I'm just going to kick start the
template which has deletion policy said
to retain click on create new stack
upload a template clicking on browse
here which will take me to find her and
this is the stat template which has been
modified
click on next
the stag team which I'm going to enter
deletion policy demo
click on next
formation stack tag which I'm going to
set as decision policy demo again
click on next we have already gone
through the review part so I'm just
going to click on create
fresh
they're my stack has just completed let
me take you back to the ec2 management
console
click on refresh
so cloud formation has recreated two new
security groups
let's verify the output
so as you can see these are the two
security groups that cloud formation
created
clicking on template and maximizing
as you can see here the modified
plate has deletion policies set to
retain across all the resources which
are the security groups
so let's see if setting the deletion
policy retain would work if I were to
delete the CloudFormation stack the
expected behavior would be that the
stack would be deleted but the security
groups should be untouched clicking on
minimize
and I'm about to delete the stack
taking you back to the ec2 management
console and clicking on refresh
as you can see the stack was deleted but
CloudFormation
did not delete the two security groups
that it provisioned thanks for watching
and happy cloud computing from all of us
here at
[Music]
you
[Music]