Automating AWS services with Amazon Q Developer Console-to-Code - Amazon Q Developer

Automating AWS services with Amazon Q Developer Console-to-Code

What is Console-to-Code?

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.

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, you can record your console actions, and generate CLI commands based on those actions, as much as you like. However, there is a limit to how many times per month you may generate code to use with the AWS CDK, or with CloudFormation, based on your recorded actions.

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.

For more information, visit the Amazon Q Developer pricing page.

Note

When you record an action, you will still be charged for the action itself, if applicable. For example, if you record yourself provisioning an Amazon EC2 instance, then you will still be charged for the instance. The free part is the recording.

Supported code formats

Console-to-Code can currently generate infrastructure-as-code (IaC) in the following languages and formats:

  • CDK Java

  • CDK Python

  • CDK TypeScript

  • CloudFormation JSON

  • CloudFormation YAML

Where can you use Console-to-Code?

Using Console-to-Code across multiple services

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 web server:

  • In the VPC console, you provision two subnets (one public and one private), security groups, NACLs, a custom routing table, and an internet gateway.

  • In the Amazon EC2 console, you provision an Amazon EC2 instance and place it in the public subnet.

  • In the Amazon RDS console, you provision an Amazon RDS DB instance and place it in the private subnet.

Even if you perform your actions in different parts of the console and they use different AWS services, Console-to-Code can include them in a single recording.

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

Granting permissions to use Console-to-Code

To use Console-to-Code, you must have:

  • Permissions to use Amazon Q on AWS websites.

  • Permissions to take whatever actions you are going to record.

  • Permissions to use Console-to-Code itself.

This is the policy for assigning permissions to use Console-to-Code:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAmazonQConsoleToCode", "Effect": "Allow", "Action": "q:GenerateCodeFromCommands", "Resource": "*" } ] }

Authenticating for Console-to-Code

At the Free tier, signing in to the AWS management console is enough to give you access to Console-to-Code.

After a designated number of code generations each month, you must authenticate to the Pro tier in order to generate more code. (You can continue to generate CLI commands at the free tier.)

To authenticate to 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 Pro.

You might have signed in to the AWS management console with IAM, or federation with IAM. In that case, if your organization administrator has enabled identity-aware sessions, then, when you reach the end of the Free tier, you will be prompted to authenticate with IAM Identity Center.

You may have signed into the console with IAM Identity Center. This scenario includes authenticating through an external identity provider that is connected to IAM Identity Center. In that case, if your IAM Identity Center identity is associated with a subscription to Amazon Q, you will already be authenticated to the Pro tier for Console-to-Code.

Using Console-to-Code

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 console of one of the integrated services (Amazon VPC, Amazon RDS, or Amazon EC2).

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

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

Step 2: Take actions

In the consoles of any of the integrated services, proceed to take any actions that you want to record.

The Console-to-Code side panel retains its own state. You can move between the consoles of the integrated services, creating one recording that involves actions for multiple services.

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.

When you have finished taking actions that you want to convert to code, choose Stop from the top of the Console-to-Code panel.

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.

  3. Select the commands that you want to use. Only the commands with checked boxes will be used in the following steps.

  4. 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.

  5. 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.

  3. 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.

  4. Choose Generate chosen language.

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