DEV Community

Danny Steenman for AWS Community Builders

Posted on • Originally published at towardsthecloud.com on

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. 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.

CloudFormation in a nutshell

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, Sceptre, 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!

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

Enter fullscreen mode Exit fullscreen mode

2. 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 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

Enter fullscreen mode Exit fullscreen mode

Install using Homebrew (macOS):

brew install cfn-lint

Enter fullscreen mode Exit fullscreen mode

Finally, you can install 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.

CloudFormation Resource Snippets for VS Code extension usage

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 that goes into more detail about its features.

4. Browsing 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

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

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

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 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. Thanks to your support, I'm able to continue doing what I enjoy the most, which is sharing my learnings with the Cloud Community.

Top comments (2)

Collapse
 
cremich profile image
Christian Bonzelet

Awesome @dannysteenman
I was not aware of this Dash tool. Right now I will test it out but I don't know if I will spend 30$ for this. Do you know if there is a open source alternative?

Collapse
 
dannysteenman profile image
Danny Steenman

You can try out Zeal, it even supports dash docset files.