Idempotent CloudFormation stack creation/update one-liner with Ansible

When developing CloudFormation templates, I regularly missed an idempotent one-liner command which does something like “create or update stack N with these parameters”, which provides a fast feedback loop.

So here it is with Ansible (and virtualenv for convenience):

1
2
3
4
virtualenv venv
source venv/bin/activate
pip install ansible boto3
ansible localhost -m cloudformation -a "stack_name=stack_name template=path/to/template region=eu-west-1 template_parameters='template_param1=bar,template_param2=baz'"

It will create a new or update an existing CloudFormation stack and wait until the operation has finished. It won’t complain if there are no updates to be performed.

PS: Michael Wittig has released a CloudFormation CLI wrapper (NPM module) for this problem, too!

Like what you read?

You can hire me or make a donation via PayPal!