[HTML payload içeriği buraya]
32.2 C
Jakarta
Monday, November 25, 2024

Convert AWS console actions to reusable code with AWS Console-to-Code, now typically accessible


Voiced by Polly

As we speak, we’re saying the overall availability (GA) of AWS Console-to-Code that makes it straightforward to transform AWS console actions to reusable code. You should utilize AWS Console-to-Code to report your actions and workflows within the console, resembling launching an Amazon Elastic Compute Cloud (Amazon EC2) occasion, and evaluate the AWS Command Line Interface (AWS CLI) instructions on your console actions. With only a few clicks, Amazon Q can generate code for you utilizing the infrastructure-as-code (IaC) format of your selection, together with AWS CloudFormation template (YAML or JSON), and AWS Cloud Improvement Equipment (AWS CDK) (TypeScript, Python or Java). This can be utilized as a place to begin for infrastructure automation and additional personalized on your manufacturing workloads, included in pipelines, and extra.

Since we introduced the preview final 12 months, AWS Console-to-Code has garnered constructive response from clients. It has now been improved additional on this GA model, as a result of we’ve got continued to work backwards from buyer suggestions.

New options in GA

  • Assist for extra providers – Throughout preview, the one supported service was Amazon EC2. At GA, AWS Console-to-Code has prolonged assist to incorporate Amazon Relational Database Service (RDS) and Amazon Digital Non-public Cloud (Amazon VPC).
  • Simplified expertise – The brand new consumer expertise makes it simpler for purchasers to handle the prototyping, recording and code era workflows.
  • Preview code – The launch wizards for EC2 cases and Auto Scaling teams have been up to date to permit clients to generate code for these assets with out really creating them.
  • Superior code era – AWS CDK and CloudFormation code era is powered by Amazon Q machine studying fashions.

Getting began with AWS Console-to-Code
Let’s start with a easy state of affairs of launching an Amazon EC2 occasion. Begin by accessing the Amazon EC2 console. Find the AWS Console-to-Code widget on the proper and select Begin recording to provoke the recording.

Now, launch an Amazon EC2 occasion utilizing the launch occasion wizard within the Amazon EC2 console. After the occasion is launched, select Cease to finish the recording.

Within the Recorded actions desk, evaluate the actions that have been recorded. Use the Sort dropdown checklist to filter by write actions (Write). Select the RunInstances motion. Choose Copy CLI to repeat the corresponding AWS CLI command.

That is the CLI command that I bought from AWS Console-to-Code:

aws ec2 run-instances 
  --image-id "ami-066784287e358dad1" 
  --instance-type "t2.micro" 
  --network-interfaces '{"AssociatePublicIpAddress":true,"DeviceIndex":0,"Teams":["sg-1z1c11zzz1c11zzz1"]}' 
  --credit-specification '{"CpuCredits":"commonplace"}' 
  --tag-specifications '{"ResourceType":"occasion","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 may be simply modified. For this instance, I up to date it to launch two cases (--count 2) of kind t3.micro (--instance-type). This can be a simplified instance, however the identical method may be utilized to different workflows.

I executed the command utilizing AWS CloudShell and it labored as anticipated, launching two t3.micro EC2 cases:

The only-click CLI code era expertise relies on the API instructions that have been used when actions have been executed (whereas launching the EC2 occasion). Its fascinating to notice that the companion display surfaces recorded actions as you full them in console. And because of the interactive UI with begin and cease performance, its straightforward to obviously scope actions for prototyping.

IaC era utilizing AWS CDK
AWS CDK is an open-source framework for outlining cloud infrastructure in code and provisioning it via AWS CloudFormation. With AWS Console-to-Code, you may generate AWS CDK code (presently in Java, Python and TypeScript) on your infrastructure workflows.

Lets proceed with the EC2 launch occasion use case. In the event you haven’t achieved it already, within the Amazon EC2 console, find the AWS Console-to-Code widget on the proper, select Begin recording, and launch an EC2 occasion. After the occasion is launched, select Cease to finish the recording and select the RunInstances motion from the Recorded actions desk.

To generate AWS CDK Python code, select the Generate CDK Python button from the dropdown checklist.

You should utilize the code as a place to begin, customizing it to make it production-ready on your particular use case.

I already had the AWS CDK put in, so I created a brand new Python CDK undertaking:

mkdir c2c_cdk_demo
cd c2c_cdk_demo
cdk init app --language python

Then, I plugged within the generated code within the Python CDK undertaking. For this instance, I refactored the code right into a AWS CDK Stack, modified the EC2 occasion kind, and made different minor modifications to make sure that the code was appropriate. I efficiently deployed it utilizing cdk deploy.

I used to be in a position to go from the console motion to launch an EC2 occasion after which all the way in which to AWS CDK to breed the identical outcome.

from aws_cdk import (
    Stack,
    aws_ec2 as ec2,
)
from constructs import Assemble

class MyProjectStack(Stack):

    def __init__(self, scope: Assemble, construct_id: str, **kwargs) -> None:
        tremendous().__init__(scope, construct_id, **kwargs)

        existing_vpc = ec2.Vpc.from_lookup(self, "ExistingVPC",
            is_default=True
        )

        occasion = ec2.Occasion(self, "Occasion",
                instance_type=ec2.InstanceType("t3.micro"),
                machine_image=ec2.AmazonLinuxImage(),
                vpc=existing_vpc,
                vpc_subnets=ec2.SubnetSelection(
                    subnet_type=ec2.SubnetType.PUBLIC
                )
        )

You may also generate CloudFormation template in YAML or JSON format:

Preview code
You may also immediately entry AWS Console-to-Code from Preview code function in Amazon EC2 and Amazon EC2 Auto Scaling group launch expertise. Which means you don’t have to really create the useful resource as a way to get the infrastructure code.

To do this out, observe the steps to create an Auto Scaling group utilizing a launch template. Nevertheless, as an alternative of Create Auto Scaling group, click on Preview code. It’s best to now see the choices to generate infrastructure code or copy the AWS CLI command.

Issues to know
Right here are some things you need to think about whereas utilizing AWS Console-to-Code:

  • Anybody can use AWS Console-to-Code to generate AWS CLI instructions for his or her infrastructure workflows. The code era function for AWS CDK and CloudFormation codecs has a free quota of 25 generations monthly, after which you’ll need an Amazon Q Developer subscription.
  • It’s advisable that you simply check and confirm the generated IaC code code earlier than deployment.
  • At GA, AWS Console-to-Code solely data actions in Amazon EC2, Amazon VPC and Amazon RDS consoles.
  • The Recorded actions desk in AWS Console-to-Code solely show actions taken in the course of the present session inside the particular browser tab, and it doesn’t retain actions from earlier classes or different tabs. Be aware that refreshing the browser tab will outcome within the lack of all recorded actions.

Now accessible
AWS Console-to-Code is out there in all business Areas. You possibly can study extra about it within the Amazon Q Developer consumer information. Give it a strive within the Amazon EC2 console and ship suggestions to the AWS re:Submit for Amazon EC2 or via your common AWS Assist contacts.

Up to date on 10 October, 2024: Documentation hyperlink up to date for “study extra”

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles