Level up CloudFormation with VS Code

If you use CloudFormation to provision your infrastructure in AWS. You definitely need these VS Code extensions and CLI tools to speed up your deployment.

For smaller projects in AWS, CloudFormation is still a relevant tool to quickly deploy infrastructure as code.

In this article, I will share 4 tools that help you build CloudFormation stacks faster and improve your productivity by 100%.

What is CloudFormation?

Managing and maintaining infrastructure in the Cloud is being automated more often to improve efficiency and more. In 2011 AWS saw that this could be improved using Infrastructure as Code and they developed a tool called CloudFormation.

CloudFormation functionality shown in a diagram
CloudFormation functionality shown in a diagram

Provisioning resources using JSON/YAML templates improved efficiency and removes repeatability a lot!

But that was not enough for some people. Several communities and even AWS started developing frameworks like CDKSceptreTroposphere, etc… These are abstraction layers that use an existing programming language like Python or Typescript to generate CloudFormation templates.

Even though we have so many tools and frameworks at our disposal, they require certain programming skills to be able to start doing what you really want to do, which is: building infrastructure in the Cloud!

For bigger projects where you work with a team, I would recommend diving deeper into one of the frameworks listed above. The benefits are tremendous:

  • Create Objects, use loops and conditions to dynamically create resources
  • Combine with IDE and take advantage of validating and testing your code before you deploy

4 tools that help you build CloudFormation stacks faster

The goal of this article is to keep things simple and the entry-level low so that many engineers and beginners in the Cloud can efficiently write infrastructure as code.

I will show that ordinary CloudFormation can still be relevant to this day and if you combine it with the right extensions it can become a game changer.

You’ll think twice next time when you want to provision infrastructure with complex frameworks for small projects.

1. Convert CloudFormation templates

There might be occasions when you still own JSON templates and want to start using the readability of the YAML structure. Seek no further cause AWS got your back with cfn_flip!

The tool converts AWS CloudFormation templates between JSON and YAML formats. For example, converting JSON to YAML:

cfn-flip -y cfn_template.json cfn_template.yml

2. CloudFormation Linting

AWS Created a tool called CloudFormation Linter which validates CloudFormation YAML/JSON templates against the CloudFormation spec. This includes checking valid values for resource properties and best practices.

Broken CloudFormation template example
Broken CloudFormation template example

The benefit of using this tool is that you can catch errors in your template before you deploy it in the Cloud. This reduces the cycle time when creating or updating CloudFormation templates.

Install the pip package first before you install the extension in VS Code.

Install using pip:

pip install cfn-lint

Install using Homebrew (macOS):

brew install cfn-lint

Finally, you can install the extension in VS Code.

3. CloudFormation auto-completion

One of the annoyances of creating actual resources is having to figure out which properties are available to configure. This can be time-consuming and you have to jump back and forth in the CloudFormation documentation to copy and paste simple stuff.

For this reason, I created an extension in VS Code to alleviate this burden and make you more efficient in writing CloudFormation templates.

The extension is called CloudFormation Resource Snippets.

VS Code CloudFormation Snippets extension example

If you wish to create an autoscaling group, for example, you can type auto , and VS Code will try to suggest which YAML snippet you want to insert.

When you see the right resource you want to insert, you press enter and it will auto-complete and add all the properties for you.

Properties that are required by the resources contain an additional comment # required to let you know that you have to fill in the details.

This extension is automatically updated every week when AWS releases/updates CloudFormation resources.

It supports all resource types which are available in CloudFormation. Intrinsic functions + conditions are supported and it contains a whole bunch of custom parameter types.

I wrote an article that goes into more detail about its features.

4. Browse CloudFormation API documentation

Dash is an API Documentation Browser and Code Snippet Manager. With this tool, you can instantly search offline documentation sets for 200+ APIs, 100+ cheat sheets, and more. You can even generate your own docsets or request docsets to be included.

In this case, we want to download the CloudFormation Template Reference Docset in the app.

Dash CloudFormation docset
Dash CloudFormation docset

The benefit of having this is that you don’t need to browse online to find a specific resource type + fetching resource types goes way quicker since the definitions are already offloaded.

To make the app even more useful, we can add the Dash VS Code extension to our editor. This will allow you to quickly find CloudFormation resource types.

If you highlight the resource type and press ctrl + h it will open the CloudFormation docset in the Dash app. This allows you to quickly find more information about the properties of the specific resource.

Invoke Dash Docset from within VS Code example

CloudFormation leveled up!

Ultimately combining ordinary CloudFormation with the right VS Code extensions can become a game-changer for your next project!

Let me know if you found this useful and if there are other extensions out there that are worth sharing!

Danny Steenman

A Senior AWS Cloud Engineer with over 9 years of experience migrating workloads from on-premises to AWS Cloud.

I have helped companies of all sizes shape their cloud adoption strategies, optimizing operational efficiency, reducing costs, and improving organizational agility.

Connect with me today to discuss your cloud aspirations, and let’s work together to transform your business by leveraging the power of AWS Cloud.

I need help with..
stacked cubes
Improving or managing my CDK App.Maximize the potential of your AWS CDK app by leveraging the expertise of a seasoned CDK professional.
Reducing AWS Costs.We can start by doing a thorough assessment of your current AWS infrastructure, identifying areas with potential for cost reduction and efficiency improvement.
Verifying if my infrastructure is reliable and efficient.We’ve created a comprehensive AWS Operations Checklist that you can utilize to quickly verify if your AWS Resources are set up reliably and efficiently.