Fix missing `aws cloudformation ensure-stack`
I am missing
aws cloudformation ensure-stack --stack-name my-stack --local-template-file my-file.yaml
to just make the infrastructure as I described it.
Current aws cli requires awkward handling like this (pseudocode):
aws cloudformation list-stacks
if stack exists
try
aws cloudformation update-stack
catch "nothing changed in your stack"
ignore
end
else
aws cloudformation create-stack
end
I hope, AWS will extend awscli some day! In the mean time, to work around the
pain of aws cli, since we are using ansible for orchestration anyway, I just
reference the cloudformation template from an ansible playbook. Bonus: you can
use some ansible, jinja2 logic or string interpolation for DRY, like e.g. using
the stage
name for both: template parameters and the name of the stack:
---
- name: Wrapper playbook for idempotent cloudformation stack handling
gather_facts: false
hosts: localhost
vars:
stage: None # please provide stage name
tasks:
- name: ensure a cloudformation stack as defined
cloudformation:
stack_name: "media-assets-{{ stage }}-stack"
template: my-local-template-file.yaml
region: eu-west-1
template_parameters:
topic: media
stage: "{{ stage }}"
If you do not use ansible playbooks anyway, here are two other alternatives:
- node.js special cfn-create-or-update tool by Michael Wittig
- very compact installation and single line ansible invocation by Soenke Ruempler