DEV Community

Cover image for Unlocking the Power of AWS Console to Code: A Game-Changer for DevOps and Infrastructure as code (IaC)

Unlocking the Power of AWS Console to Code: A Game-Changer for DevOps and Infrastructure as code (IaC)

AWS is announcing the general availability of Console to Code, powered by Amazon Q Developer. Console to Code makes it simple, fast, and cost-effective to move from prototyping in the AWS Management Console to building code for production deployments. Customers can generate code for their console actions in their preferred format with a single click. The generated code helps customers get started and bootstrap their automation pipelines for tasks.

Console to Code makes it easy to convert actions performed in the console into reusable code, using the language of your choice. Customers use the AWS Management Console to learn and prototype cloud solutions, and using Console to code they can automatically capture those actions, and generate code for them. Console to Code provides code in CLI, Cloudformation and CDK formats. CLI code is recorded as customers take actions in console and replicates underlying AWS best practices. Customers can also generate CDK and Cloudformation code using Amazon Q Developer GenAI capability. This code follows AWS guided best practices to perform reliable deployments. Customers can copy or download the code and iterate on it to make it production ready. Customers no longer have to make a choice between Console or Infrastructure-as-Code (IaC).

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 allows users to generate infrastructure-as-code (IaC) from manual console interactions. It simplifies the process of converting AWS Console configurations and settings into code snippets in JSON, YAML, or Python (Boto3), which can be reused in AWS CloudFormation or other IaC tools.
Instead of manually configuring AWS resources through the Console every time, developers and engineers can now generate reusable code that accelerates deployment, enhances consistency, and supports 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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 scenario of launching an Amazon EC2 instance. Start by accessing the Amazon EC2 console. Locate the AWS Console-to-Code widget on the right and choose Start recording to initiate the recording.
Image description

Now, launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console. After the instance is launched, choose Stop to complete the recording.
Image description

In the Recorded actions table, review the actions that were recorded. Use the Type dropdown list to filter by write actions (Write). Choose the RunInstances action. Select Copy CLI to copy the corresponding AWS CLI command.
Image description

This is the CLI command that I got from AWS Console-to-Code:

aws ec2 run-instances \
  --image-id "ami-066784287e358dad1" \
  --instance-type "t2.micro" \
  --network-interfaces '{"AssociatePublicIpAddress":true,"DeviceIndex":0,"Groups":["sg-1z1c11zzz1c11zzz1"]}' \
  --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"
Enter fullscreen mode Exit fullscreen mode

This command can be easily modified. For this example, I updated it to launch two instances (--count 2) of type t3.micro (--instance-type). This is a simplified example, but the same technique can be applied to other workflows.
I executed the command using AWS CloudShell and it worked as expected, launching two t3.micro EC2 instances:
Image description

The single-click CLI code generation experience is based on the API commands that were used when actions were executed (while launching the EC2 instance). Its interesting to note that the companion screen surfaces recorded actions as you complete them in console. And thanks to the interactive UI with start and stop functionality, its easy to clearly scope actions for 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 use case. If you haven’t done it already, in the Amazon EC2 console, locate the 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 from the dropdown list.
Image description

You can use the code as a starting point, customizing it to make it production-ready for your specific use case.
Image description

You can also generate CloudFormation template in YAML or JSON format:
Image description

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. This means that you don’t have to actually create the resource in order to get the infrastructure code.
To try this out, follow 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.
Image description

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. Note that refreshing the browser tab will result in the loss of all recorded actions.

Top comments (0)