Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Painlessly Create and Update a CloudFormation Stack

DZone's Guide to

How to Painlessly Create and Update a CloudFormation Stack

Using AWS CLI to create a CloudFormation stack on the first run of the pipeline, while you need to update the stack for all following pipeline runs can be painful.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

When integrating CloudFormation into your CI/CD pipeline, you are faced with the challenge of creating a CloudFormation stack on the first run of the pipeline, while you need to update the stack for all following pipeline runs. If you use the AWS CLI, this is painful.

You may also have your code and template in the same repository. Therefore, code changes without the template. However, the AWS CLI threats an update without changes to a stack as an error which is not the behavior that you need in your pipeline.

cfn-create-or-update can create or update a CloudFormation stack. If no updates are to be performed, no error is thrown. cfn-create-or-update behaves exactly as the AWS CLI regarding input values, and the output will be different.

Installation

To install the CLI cfn-create-or-update tool, run:

npm install -g cfn-create-or-update        

To create or update a stack, run:

cfn-create-or-update --stack-name test --template-body file://template.yml        

The first time you run this command, a stack will be created. The second time, an update will be performed — but only if the template has changed.

CLI Parameters

cfn-create-or-update behaves exactly as the AWS CLI regarding input values. Supported parameters (as documented in the AWS CLI create-stack or update-stack):

cfn-create-or-update
--stack-name
--template-body
--template-url
--parameters
--capabilities 
--resource-types
--role-arn
--stack-policy-body
--stack-policy-url
--notification-arns
--tags

Global parameters (as documented in the AWS CLI):

--profile
--region

Only used during create, otherwise ignored (as documented in the AWS CLI create-stack):

--disable-rollback | --no-disable-rollback
--timeout-in-minutes
--on-failure

Only used during update, otherwise ignored (as documented in the AWS CLI update-stack):

--use-previous-template | --no-use-previous-template]
--stack-policy-during-update-body
--stack-policy-during-update-url

Additional parameter, to wait for create complete / update complete.

---wait        

cfn-create-or-update is available on GitHub for free (MIT license).

Other solutions to this problem:

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:
devops ,cli ,aws ,cloudformation ,stacks ,tutorial

Published at DZone with permission of Michael Wittig, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}