shou2017.com
JP

How to easily create CloudFormation

Fri May 15, 2020
Sat Aug 10, 2024
AWS

When developing on AWS, you don’t want to keep clicking around the console forever. Instead, you want to template your configuration so you can always recreate the same environment. That’s why you use AWS CloudFormation, but it’s harder than you might think!

Most of the information you find by searching is console explanations, and the official documentation is just a bunch of unfamiliar terms, so you end up googling over and over.

In this post, I’ll introduce a way I found to easily create CloudFormation templates.

First, create a sample from the console

Instead of looking at the CloudFormation documentation from the start, it’s faster to use the console to create something that works as expected, and then study it.

Convert console resources to CloudFormation

Let’s try with the easiest one, AWS::IAM::Role.

Go to IAM in the console, move to Roles, and select the policy summary.

How to easily create CloudFormation

This policy summary lets you check if the created policy works correctly, which is convenient.

Once you’ve checked the policy, convert it to YAML. Use aws-cfn-template-flip.

aws-cfn-template-flip is a great tool for converting CloudFormation templates between JSON and YAML. CloudFormation templates are easier to read in YAML, but the policy summary is in JSON, so use this tool to convert it.

Install

% pip install cfn-flip

Convert from JSON to YAML

% cfn-flip test.json test.yml

If you refer to the YAML you just created, I think it will be easier to make CloudFormation templates.

See Also