AWS is announcing the general availability of Console to Code, powered by Amazon Q Developer. which streamlines the transition from prototyping within the AWS Management Console to creating production-ready code. This tool allows users to easily generate code for console actions in their chosen format with just one click. By providing starter code, it helps users quickly set up and initiate automation pipelines, simplifying the path to production deployment.
The tool allows users to easily translate actions performed in the console into reusable code in a language of their choice. While customers often use the AWS Management Console for learning and prototyping, Console to Code captures these actions and converts them into code. It supports CLI, CloudFormation, and CDK formats. The CLI code is generated in real-time as users interact with the console, following AWS best practices. Additionally, Amazon Q Developer GenAI capability generates CDK and CloudFormation code, which adheres to guided AWS best practices for reliable deployments. Customers can download or copy the code, making it easy to customize and adapt for production use. This eliminates the need to choose between the console or Infrastructure-as-Code (IaC) solutions.
Console to Code, powered by Amazon Q Developer, is generally available in commercial regions for Amazon Elastic Compute Cloud (EC2), Amazon Virtual Private Cloud (VPC) and Amazon Relational Database Service (RDS).**** Learn more about Console-to-Code.
AWS Console to Code?
AWS Console to Code enables users to automatically convert manual console configurations into infrastructure-as-code (IaC). It streamlines the process by transforming AWS Console settings and configurations into code snippets in formats like JSON, YAML, or Python (Boto3), which can be integrated with AWS CloudFormation or other IaC tools.
Rather than configuring AWS resources manually through the Console for each task, developers and engineers can now generate reusable code. This approach speeds up deployments, ensures consistency across environments, and promotes automation.
How AWS Console to Code Benefits DevOps
The DevOps approach emphasizes automation, collaboration, and continuous integration/continuous deployment (CI/CD) pipelines to optimize development and operational workflows. AWS Console to Code is particularly beneficial in this context due to its potential to:
- Accelerate Automation: By generating code for cloud resources, DevOps teams can speed up the automation process. Instead of manually recreating infrastructure configurations, engineers can quickly turn console actions into code, which can be reused across multiple environments, promoting efficiency in DevOps pipelines.
- Consistency Across Environments: Code-generated configurations ensure that infrastructure is consistently deployed across development, staging, and production environments. This consistency minimizes configuration drift and errors due to manual intervention, enhancing overall system reliability.
- User-Friendly Infrastructure Setup: For users less familiar with IaC languages, AWS Console to Code provides an intuitive way to configure infrastructure directly from the console, then generate the corresponding code. This reduces the learning curve for infrastructure automation, making it more accessible to a broader audience.
- Seamless Code Generation: Users can leverage the tool to manage small to medium-sized cloud infrastructures without needing deep knowledge of code writing. Once the desired infrastructure is created via the AWS Console, it can be exported as reusable code that can be integrated into existing IaC templates.
New features in GA
- Support for more services – During preview, the only supported service was Amazon EC2. At GA, AWS Console-to-Code has extended support to include Amazon Relational Database Service (RDS) and Amazon Virtual Private Cloud (Amazon VPC).
- Simplified experience – The new user experience makes it easier for customers to manage the prototyping, recording and code generation workflows.
- Preview code – The launch wizards for EC2 instances and Auto Scaling groups have been updated to allow customers to generate code for these resources without actually creating them.
- Advanced code generation – AWS CDK and CloudFormation code generation is powered by Amazon Q machine learning models.
Getting started with AWS Console-to-Code
Let’s begin with a simple of launching an Amazon EC2 instance. Start by accessing the Amazon EC2 console. Go to the AWS Console-to-Code widget on the right and choose Start recording to initiate the recording.
Now, launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console. After launched, choose Stop to complete the recording.
In the Recorded actions table, review the actions that were recorded. Use the Type list to filter by write actions (Write). Choose the RunInstances
action. Select Copy CLI to copy AWS CLI command.
This is the CLI command that I got from AWS Console-to-Code:
aws ec2 run-instances \
--image-id "ami-066554784287e358dad1" \
--instance-type "t2.micro" \
--network-interfaces '{"AssociatePublicIpAddress":true,"DeviceIndex":0,"Groups":["sg-1aa"]}' \
--credit-specification '{"CpuCredits":"standard"}' \
--tag-specifications '{"ResourceType":"instance","Tags":[{"Key":"Name","Value":"c2c-demo"}]}' \
--metadata-options '{"HttpEndpoint":"enabled","HttpPutResponseHopLimit":2,"HttpTokens":"required"}' \
--private-dns-name-options '{"HostnameType":"ip-name","EnableResourceNameDnsARecord":true,"EnableResourceNameDnsAAAARecord":false}' \
--count "1"
This command can be easily modified. Updated it to launch two instances (--count 2
) of type t3.micro
(--instance-type
). This is a simplified.
I executed the command using AWS CloudShell and it worked as expected, launching two t3.micro
EC2 instances:
The one-click CLI code generation is driven by the API commands triggered during actions, such as when launching an EC2 instance. Notably, the companion screen displays the recorded actions in real-time as you complete them in the console. With its interactive UI, which includes start and stop controls, you can easily define and limit the scope of actions for more efficient prototyping.
IaC generation using AWS CDK
AWS CDK is an open-source framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation. With AWS Console-to-Code, you can generate AWS CDK code (currently in Java, Python and TypeScript) for your infrastructure workflows.
Lets continue with the EC2 launch instance. If you haven’t done it already, in the Amazon EC2 console, Go to AWS Console-to-Code widget on the right, choose Start recording, and launch an EC2 instance. After the instance is launched, choose Stop to complete the recording and choose the RunInstances
action from the Recorded actions table.
To generate AWS CDK Python code, choose the Generate CDK Python button.
You can use the code as a starting point, customizing it to make it production-ready.
You can also generate CloudFormation template in YAML or JSON format:
Preview code
You can also directly access AWS Console-to-Code from Preview code feature in Amazon EC2 and Amazon EC2 Auto Scaling group launch experience.
The steps to create an Auto Scaling group using a launch template. However, instead of Create Auto Scaling group, click Preview code. You should now see the options to generate infrastructure code or copy the AWS CLI command.
Things to know
Here are a few things you should consider while using AWS Console-to-Code:
- Anyone can use AWS Console-to-Code to generate AWS CLI commands for their infrastructure workflows. The code generation feature for AWS CDK and CloudFormation formats has a free quota of 25 generations per month, after which you will need an Amazon Q Developer subscription.
- It’s recommended that you test and verify the generated IaC code code before deployment.
- At GA, AWS Console-to-Code only records actions in Amazon EC2, Amazon VPC and Amazon RDS consoles.
- The Recorded actions table in AWS Console-to-Code only display actions taken during the current session within the specific browser tab, and it does not retain actions from previous sessions or other tabs.