Skip to main content
  1. Articles/

CloudFormation Language Server saves me a lot of time, and it's a pleasure to use

One of the perks of being an AWS Community Builder is having the opportunity to preview new features and provide feedback to the service teams.

A month ago, I attended an online session that presented a feature I had longed for when I started working with AWS and CloudFormation five years ago: the official AWS CloudFormation Language server.

It is open-source and follows the LSP standards. You can find the project and all the features here: https://github.com/aws-cloudformation/cloudformation-languageserver I think something that really changes the development experience is the out-of-the-box integration with AWS Toolkit: its integration with the IDE takes the development experience to a new level. As we’ll see, there are plenty of features that will save everyone a lot of time

Why CloudFormation matters #

There are plenty of IaC languages out there, but I believe that for infrastructure projects, a rock-solid approach is necessary, supported by robust technology.

While Terraform, CDK, OpenTofu, and others can offer a developer-friendly approach, I found that they typically have several downsides. I don’t want to start a flame, but:

  1. Terraform and OpenTofu diverged, with a battle going on between the two organizations
  2. CDK is dependent on Node.js and TypeScript. I think it is a good framework, but you cannot deploy a project and forget to periodically update all the libraries and the framework; otherwise, suddenly one day, you will find out that you cannot deploy anymore. This is not good if you have to manage critical infrastructure components
  3. CloudFormation offers a stable interface. Since its introduction, there have been no instances of the language changing, thereby introducing incompatibilities.

I am not saying that you have to stick to CloudFormation (I also use CDK): as always, consider the use case and use the right technology. Now, without further ado, let’s explore the new features!

Install ASW Toolkit #

I use Visual Studio Code, but the instructions and the experience are the same for other VS Code-based editors

If you haven’t done it yet, this is the time

Search for “AWS Toolkit” in extensions:

Search AWS Toolkit

Once you install the AWS toolkit, you can use your AWS Credentials to log in. I prefer using IAM Identity Center, even for my personal projects because I can use multiple accounts, and clean up resources with a single click by closing the related AWS account when I finish my experimentations.

A big benefit of using AWS IAM Identity center is that you don’t have to generate and store IAM access keys. If you don’t generate static credentials, you don’t have the chance of acidentally leak them :)

Toolkitlogin

I will not show you the process of configuring IAM Identity center, but once you set it up, the only thing you need to specify is your start URL, and log in using your browser.

The entire authentication flow is smooth and integrated into the IDE, even with account and role selection

Toolkit login
Toolkit login

Once you complete these steps you’re all set, and you can start developing.

Create a CloudFormation project #

Once you complete the setup, you will find a new set of options in the command palette (CMD+Shift+P on Mac), just search for CloudFormation

Command Palette

From here, you can create a new CloudFormation project, and specify environments

New Project

Start Developing #

Once you set up the project (done in a matter of seconds), you can create a new template using the command palette again, or create a file inside the project foder.

I prefer YAML syntax (and I think you should too, since it allows for comments). When you create a new file, you will find an empty, commented basic template:

Empty Template

Suggestions Everywhere #

The good thing is that, right after you click on the editor, you will immediately find suggestions, as we will see suggestions are scoped to the sections of the CloudFormation file. These are suggestions for the sections.

Template Suggestions

And once you create the Resources section and a resource, suggestions for properties will pop up. This speeds up my development time significantly, since I don’t remember every property for all CloudFormation resources :)

Properties Suggestions

Needless to say, it works also for configurations

Properties

Refactor and extract parameters #

And, once you finish setting up your resources, you can extract properties, avoiding hardcoding parameters (and saving time by copying and pasting names in your templates to match the declaration)

Extract Paramters

Automatic checks and warnings #

I just finished declaring my resource, focusing on what matters to the project, but I see a blue warning; maybe I forgot something, or something isn’t right?

Resource Warnings

I can find what’s going on just by hovering and see that cfn-guard is (rightfully) complaining about something I wasn’t focused on

Resource warnings

Thanks to these warnings, I can now add (at least) Encryption and block public access to my resources. This is a real time-saver. You will avoid noncompliance warnings after you deploy, with a real shift-left approach to developing things with security in mind from the start.

Reducing the feedback loop time is always a good thing: avoiding reworks also improves your mood, too!

Cfn-guard isn’t the only tool that will help improve your code; cfn-lint is here to help, too.

In this example, I declared an unused parameter:

cfn-lin

Last, but not least for the development part: if your template is getting crowded, you can always find everything in the Outline section ![Resource outline][16-Outline.png]

Project Deployment #

Another amazing feature is the deployment integration. You can control everything in the IDE without needing to switch back and forth to reach the AWS console. Let’s see how everything works

Just bring up the command palette, and search for deploy:

Deploy

You can specify parameters on the fly:

Deployment parameters

Once you specify your parameters, the extension can automatically save them in a JSON file for you, saving time and avoiding errors in parameter name mapping.

The deployment will automatically create a changeset, and you can review and approve it inside VSCode, without leaving the IDE; just look at the Resource panel:

Resource explorer changeset
Changeset validation
When you click on “Deploy Changes”, the deployment will start, and you can track its progress.

I intentionally set an incorrect parameter for the intelligent tiering configuration. You can see the error directly in the output section!

Deployment Failure

The only downside in this case is that, since the stack is in the “CREATE FAILED” status, you need to delete it from the AWS Console

Deploying with the correct parameter makes everything better:

Successful Deployment

What’s next #

I am still exploring the extension and all of its full capabilities (like resource import). I’m sure that in the future, many features will be added to streamline the CloudFormation development process.

In this example, I have purposely disabled every AI coding companion to demonstrate its standalone capabilities. When combined with an AI assistant, the CloudFormation language server will let you develop things so fast that you will forget about how much time you spent troubleshooting an indentation issue!

Have you tried other CloudFormation extensions? Let me know in the comments!

Damiano Giorgi
Author
Damiano Giorgi
Ex on-prem systems engineer, lazy and prone to automating boring tasks. In constant search of technological innovations and new exciting things to experience. And that’s why I love Cloud Computing! At this moment, the only ‘hardware I regularly dedicate myself to is that my bass; if you can’t find me in the office or in the band room try at the pub or at some airport, then!

comments powered by Disqus