Level up CloudFormation with VS Code
Tags: aws, cloudformation, vscode
Published: 2021-11-02 18:58:59

---
title: Level up CloudFormation with VS Code
published: true
date: 2020-03-23 17:12:21 UTC
tags: aws, cloudformation, vscode
canonical_url: https://towardsthecloud.com/level-up-cloudformation-vscode
---

 **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. I want to share 4 tools that help you create CloudFormation stacks faster than you could imagine.

## What is CloudFormation?

Managing and maintaining infrastructure in the Cloud is being automated more often to improve efficiency and more. Since 2011 AWS saw that this could be improved using Infrastructure as Code and they developed a tool called [CloudFormation](https://aws.amazon.com/cloudformation/).

![CloudFormation in a nutshell](https://cdn.hashnode.com/res/hashnode/image/upload/v1597855075225/EzUQoJj4-.jpeg)

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 [CDK](https://aws.amazon.com/cdk/), [Sceptre](https://github.com/Sceptre/sceptre), [Troposphere](https://github.com/cloudtools/troposphere) 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

The goal of this article is to keep things simple and the entry-level low so 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 gamechanger. You’ll think twice next time when you want to provision infrastructure with complex frameworks for small projects.

## 1. Converting templates

There might be occasions where 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](https://github.com/awslabs/aws-cfn-template-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. Linting

AWS Created a tool called [CloudFormation Linter](https://github.com/aws-cloudformation/cfn-python-lint) which validates CloudFormation YAML/JSON templates against the CloudFormation spec. This includes checking valid values for resource properties and best practices.

![Broken template example](https://cdn.hashnode.com/res/hashnode/image/upload/v1597855118769/j_AKL5Gmx.jpeg)

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](https://marketplace.visualstudio.com/items?itemName=kddejong.vscode-cfn-lint) the extension in VS Code.

## 3. 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](https://marketplace.visualstudio.com/items?itemName=dsteenman.cloudformation-yaml-snippets).

![CloudFormation Resource Snippets for VS Code extension usage](https://cdn.hashnode.com/res/hashnode/image/upload/v1597855040083/wEH0Z-nTN.gif)

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 another [article](https://towardsthecloud.com/autocomplete-cloudformation-resources-vs-code) that goes into more detail about its features.

## 4. Browsing documentation

[Dash](https://kapeli.com/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](https://cdn.hashnode.com/res/hashnode/image/upload/v1597855015276/sDkRi7Fgg.jpeg)

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](https://marketplace.visualstudio.com/items?itemName=deerawan.vscode-dash) 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1597854897482/9rN0Vx5SdE.gif)

## CloudFormation leveled up!

Ultimately combining ordinary CloudFormation with the right VS Code extensions can become a game-changer for your next project! If you liked this and you happen to develop in Python. I can recommend you to read my other article in which I share the 10 Best VS Code extensions for Python:

[https://towardsthecloud.com/10-best-vs-code-extensions-for-python](https://towardsthecloud.com/10-best-vs-code-extensions-for-python)

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

* * *

👋 **Enjoyed this article?** Reach out in the comments below or on [Twitter](https://twitter.com/dannysteenman) to let me know what you think of it.

If you found some **value** in reading this, please consider showing your support by [sponsoring me](https://towardsthecloud.com/sponsor). Thanks to your support, I'm able to continue doing what I enjoy the most, which is sharing my learnings with the Cloud Community.