DEV Community

Cover image for How to Convert AWS Clicks into CDK/CloudFormation (The EASY Way)

How to Convert AWS Clicks into CDK/CloudFormation (The EASY Way)

The Manual Grind is Over

Let's be real: setting up infrastructure in the AWS Management Console is a right of passage. We've all been there—clicking through menus, configuring settings, and trying to remember every single step we took. It works for a one-off task, but what happens when you need to do it again? And again? It's slow, error-prone, and doesn't scale.

For years, the answer has been Infrastructure as Code (IaC) using tools like AWS CloudFormation or the AWS Cloud Development Kit (CDK). But this comes with a steep learning curve. What if you could get the best of both worlds? What if you could perform your setup once in the console and have AI generate the code for you?

That's exactly what Console-to-Code, a powerful feature in Amazon Q Developer, does. It watches your actions in the console and magically transforms them into clean, ready-to-use IaC.


Why Console-to-Code is a Game-Changer 🚀

This isn't just another tool; it's a fundamental shift in how we can approach cloud automation.

  • Bridge the Skills Gap: New to IaC? No problem. Use the visual console you're comfortable with and get high-quality code as your output. It's an incredible way to learn by doing.
  • Massive Time Saver: Instead of spending hours writing YAML or TypeScript from scratch, you can generate a solid baseline in minutes. This dramatically speeds up prototyping and deployment.
  • Enforce Consistency and Best Practices: By converting manual setups into code, you create a repeatable, reliable process. This ensures every environment you spin up is identical, eliminating the "it worked on my machine" problem for infrastructure.
  • Multi-Language Support: Whether you're a fan of Python, Java, TypeScript with the AWS CDK, or prefer the simplicity of CloudFormation (JSON/YAML), Console-to-Code has you covered.

From Clicks to Code: Your 3-Step Guide

Ready to try it out? The process is incredibly straightforward. Here’s how to turn your console actions into reusable code.

Step 1: Hit Record

First, you need to tell Amazon Q to start watching.

  1. Log in to your AWS Management Console.
  2. Navigate to a supported service like VPC, RDS, or EC2.
  3. On the far right edge of your browser window, you'll see the Console-to-Code icon. Click it.
  4. Simply click "Start recording."

That's it! The tool is now actively recording every infrastructure-related action you take.

Step 2: Build Your Infrastructure

Now for the fun part. Go through the console and perform the tasks you want to automate.

  • Launch an EC2 instance.
  • Create a new S3 bucket and configure its policies.
  • Set up a VPC with subnets and route tables.

You can even move between different services during a single recording session. The Console-to-Code panel will keep track of everything you do.

Step 3: Generate Your Code

Once you've completed your setup, it's time to get your code.

  1. In the Console-to-Code panel, you'll see a list of all the actions you performed.
  2. Review and select the specific actions you want to include in your IaC template.
  3. At the bottom of the panel, choose your desired output format from the dropdown menu (e.g., AWS CDK - Python or CloudFormation - YAML).
  4. Click the "Generate chosen language" button.

Instantly, the panel will display the generated code. You'll not only get the IaC template but also the equivalent CLI commands for your reference.


Final Thoughts & Best Practices

Console-to-Code is an incredibly powerful feature for accelerating your cloud journey. To get the most out of it:

  • Plan Your Steps: Have a clear idea of what you want to build before you start recording to keep your generated code clean and focused.
  • Review the Output: The generated code is a fantastic starting point, but always review it to understand what's happening and see if you can make any custom tweaks.
  • Use it as a Learning Tool: If you're new to IaC, generate code for simple tasks first. Study the output to understand how resources are defined and linked. It’s one of the most practical ways to learn.

The era of choosing between the easy-to-use console and powerful automation is over. With Console-to-Code, you can finally have both.

Happy building!


Connect with the Author

Thanks for reading! I'm Yeshwanth L M, an AWS Community Builder passionate about making cloud and DevOps accessible to everyone. If you found this article helpful, let's connect!

Top comments (0)