AWS Console-to-Code Converts Console Actions to Code

                                   

Code on the AWS Console

Now generally available (GA), AWS Console-to-Code simplifies the process of converting AWS console operations into reusable code. For instance, you may use AWS Console-to-Code to capture your actions and processes on the console when you start an Amazon Elastic Compute Cloud (Amazon EC2) instance. The AWS Command Line Interface (AWS CLI) commands for your terminal operations may then be evaluated.

With just a few clicks, Amazon Q can produce code for you using the infrastructure-as-code (IaC) format of your choice, such as the AWS Cloud Formation template (YAML or JSON) or the AWS Cloud Development Kit (AWS CDK) (TypeScript, Python, or Java). This may be used as a basis for infrastructure automation, integrated into pipelines, and further customized for your production workloads.

Since the preview was released last year, AWS Console-to-Code has received positive feedback from users. It has been much improved in this GA version as it has been working backwards from user input.

The new features of GA

  • Promotion of supplementary services During the trial, the only service supported was Amazon EC2. At GA, AWS Console-to-Code now supports Amazon Relational Database Service (RDS) and Amazon Virtual Private Cloud (Amazon VPC).
  • Simplified experience: With the new user interface, customers can now manage the prototyping, recording, and code generation processes more simply.
  • Preview code: With improvements to the launch wizards, customers may now write code for Auto Scaling groups and EC2 instances without actually setting them up.
  • Advanced code generation: AWS CDK and CloudFormation code is created using Amazon Q machine learning models.

How to get started with Console-to-Code on AWS

First, let's look at a simple example of how to launch an Amazon EC2 instance. First, launch the Amazon EC2 console. Locate the AWS Console-to-Code widget on the right and choose Start recording to start recording.

Next, launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console. After launching the instance, choose Stop to end the recording.

Look at the actions that have been recorded in the Recorded actions table. Use the Type dropdown option to filter by writing activities (writing). Choose the RunInstances action. Choose Copy CLI to copy the appropriate AWS CLI command.

This command is easy to modify. You may change it to begin two instances (–count 2) of type t3.micro (–instance-type) for this example. This is a simple example, but the technique may be applied to different operations.

The command may be executed using AWS CloudShell, and it successfully started two t3.micro EC2 instances as intended:

The single-click CLI code generating process is based on the API commands that were used when actions were taken (during the EC2 instance start). It's interesting to note that the companion screen shows the recorded activities when you complete operations in the console. Additionally, the start and stop features of the interactive user interface make it easy to define the scope of prototyping operations.

Using AWS CDK to create IaC

Cloud architecture is specified in code using the AWS CDK, an open-source framework, and provisioned using AWS CloudFormation. With AWS Console-to-Code, you can write AWS CDK code for your infrastructure operations. Available right now in TypeScript, Python, and Java.

Now let's discuss the EC2 launch instance use case. If you haven't already, find the AWS Console-to-Code widget on the right side of the Amazon EC2 console, choose Start recording, and then launch an EC2 instance. To complete the recording once the instance has begun, choose the RunInstances action from the Recorded activities table and click Stop.

To start creating AWS CDK Python code, choose the Generate CDK Python button from the dropdown menu.

The code may be used as a starting point or modified to make it production-ready for your specific use case.

Since you already had the AWS CDK installed, you created a new Python CDK project:

After that, the produced code was added to the Python CDK project. The code was refactored into an AWS CDK Stack, the EC2 instance type was changed, and a few other minor tweaks were done to ensure it was appropriate for this application. It was successfully deployed using CDK deploy.

By starting an EC2 instance via the console action and then proceeding all the way to the AWS CDK, you may achieve the same result.

You may also create CloudFormation templates in YAML or JSON format:

View the code

Additionally, you may use AWS Console-to-Code directly by using the Preview code feature in Amazon EC2 and the Amazon EC2 Auto Scaling group launch experience. This suggests that the infrastructure code may be acquired without the resource being created.

To test this, follow the steps to create an Auto Scaling group using a launch template. However, instead of selecting Create Auto Scaling group, click Preview code. You should now see the choices to generate infrastructure code or repeat the AWS CLI operation.

Things to consider

  • Be mindful of the following while utilizing AWS Console-to-Code:
  • Anyone may utilize AWS Console-to-Code to develop AWS CLI commands for their infrastructure operations. The code generation capability for AWS CDK and CloudFormation formats has a free monthly limit of 25 generations; above that, an Amazon Q Developer membership is needed.
  • It is recommended that you verify and validate the produced IaC code before deploying.
  • AWS Console-to-Code at GA only records activities in the Amazon EC2, Amazon VPC, and Amazon RDS consoles.
  • The Recorded activities table in AWS Console-to-Code only displays actions taken inside the current browser tab; it does not save actions from previous sessions or other tabs. Note that when the browser tab is refreshed, all recorded activities will be deleted.

Now available

AWS Console-to-Code is available in all commercial regions. More details about it may be found in the Amazon Q Developer user handbook. Try it out in the Amazon EC2 interface and send an email with your ideas to your usual AWS Support contacts or the AWS re:Post for Amazon EC2.

Post a Comment

0 Comments