Cleaning passive CloudFormation stacks

Jenkins pipeline for clearing cloud formation stacks

Blue-Green deployment from CloudFormation is one of the coolest thing on aws.

You just need to use the templates provided by AWS, make the necessary changes as per your requirement and save it on S3 bucket.

Create the stack from AWS console by putting the URL of your S3 resource (path of a template stored on S3 bucket ).

Switch your AutoScaling group from Green to Blue, and your Green (passive) will soon changes into Blue (active) and vice-versa.

Now to clear your passive stack, create a Jenkins pipeline, example given below.

So, above pipeline will execute a code “./”, which will display the lists of stacks on Interactive Terminal off Jenkins.

Along with that, it will take the input from the user to delete the stack with StackName.

Pass the StackName from the list and it will delete the Passive Stack.


Access key ID: xxxx:xxxxx:xxxxxxxx
Secret access key: xxxxxxxx:xxxxxxx:xxxxxxx

Note: The advance way of deleting the stack without any user input in interactive Jenkins terminal is to pass the active stack (Name) to the “”, for active stack details you need to use aws cli, and fetch the stack name from ASG, for more details try to learn aws cli.

Please go through the script by clicking on “” and ““, try to understand the logic before any type of implementation and make the necessary changes if requires.

Leave a Reply