How do I automate AWS services with Amazon Q Developer Console to Code?

4 minute read
Content level: Intermediate
0

Console-to-Code is a feature of Amazon Q Developer that can help you write code to automate your use of other AWS services. Console-to-Code records your console actions, then uses generative AI to suggest code in your preferred language and format. Console-to-Code works across multiple services, saving its own state for as long as your browser tab is open. For example, you may record your actions during a complete setup of a VPC

AWS services that support Console-to-Code

Currently, Console-to-Code is available to record your actions when using the AWS management console with the following services:

  • Amazon EC2
  • Amazon VPC
  • Amazon RDS

Tiers of service

Since Console-to-Code is a part of Amazon Q Developer, your use of it is subject to Amazon Q Developer’s tiers of service.

  • At the Free tier, there is no fixed monthly limit to the number of times you can record your console actions and generate CLI commands based on those actions. However, there is a limit to how many times per month you can generate code to use with the AWS CDK or AWS CloudFormation based on your recorded actions. To access the Free tier, sign into the AWS Management Console. After you reach the monthly code generations limit, you must authenticate to the Pro tier in order to generate more code.
  • At the Pro tier, there is no fixed monthly limit to the number of times you can generate code for the AWS CDK or CloudFormation. To access the Pro tier, you must be a user registered with IAM Identity Center, and your IAM Identity Center identity must be subscribed to Amazon Q Developer Pro. For more information, see Authenticating to your Amazon Q Developer Pro subscription or contact your AWS administrator.

Using Console-to-Code (Example : Create a VPC)

Using Console-to-Code consists of three steps.

Step 1: Start recording

To start recording with Console-to-Code, use the following procedure.

  1. Go to the VPC console
  2. On the right edge of the browser window, choose the Console-to-Code icon.

Enter image description here

Enter image description here

  1. In the Console-to-Code side panel, choose Start recording.

Enter image description here

Step 2 : Take Actions

  1. Create VPC in the VPC console.

Enter image description here

  1. The Console-to-Code side panel will retain your actions until your Console-to-Code session ends. The session will end when you close the browser tab, or when your AWS Management Console session ends, whichever comes first.
  2. When you have finished taking actions that you want to convert to code, choose Stop from the top of the Console-to-Code panel.
  3. Before creation of the resources (here VPC) you can Preview the Code

Enter image description here

Step 3 : Gather CLI commands and generating code

You can follow either Step 3a or Step 3b.

Step 3a : Gather CLI commands

To use Console-to-Code to generate CLI commands based on your actions, use the following procedure.

  1. In the Console-to-Code panel, review your recorded actions. You can filter the recorded actions using the dropdown, search box, or filter widget at the top of the Console-to-Code panel.
  2. At the top of the Console-to-Code panel, toggle the Show CLI setting. This will display the CLI command corresponding to each selected action.

Enter image description here

  1. Select the commands that you want to use. Only the commands with checked boxes will be used in the following steps.
  2. Consolidate the CLI commands. Near the bottom of the Console-to-Code panel, choose the accordion icon (^). The CLI commands that you selected will appear by themselves in the panel.

Enter image description here

  1. Copy or download your chosen commands.

To learn more about the AWS CLI, see What is the AWS Command Line Interface? in the AWS Command Line Interface User Guide.

Step 3b : Generate Code

  1. In the Console-to-Code panel, review your recorded actions. You can filter the recorded actions using the dropdown, search box, or filter widget at the top of the Console-to-Code panel.
  2. Select the actions that you want to convert into code. Only the actions with checked boxes will be used in the following steps.

Enter image description here

  1. Indicate the type of code that you want to generate. From the reverse dropdown menu at the lower right of the Console-to-Code panel, select the language and (if applicable) format of the code to be generated.

Choose Generate chosen language.

  1. The generated code will appear, along with the equivalent CLI commands.

Enter image description here

  1. Copy or download your chosen template.