AWS Introduces Console-to-Code (Preview): Here is Your Step-by-Step guide !
Tags: programming, tutorial, aws, productivity
Published: 2024-01-16 04:10:26

Imagine this: you're doing stuff on AWS Management Console, and magically, some angel understands everything you do. It hands you a CloudFormation template at the end, making your next project a breeze to kick off. Sounds like a wish, right? Well, a few months ago, it was just that – a wish. But guess what? Not anymore! 

Amazon Web Services (AWS) has introduced AWS Console-to-Code in preview – a super-cool GenAI powered tool that turns what you do on the AWS Management Console into real code for your projects. With Console-to-Code, you can convert your console moves into reusable code. No more choosing between clicking around on the console and writing code – this tool gives you the best of both worlds.

Please note that the feature is currently in preview and has limited capabilities. We'll also understand its current limitations.

Let's bring the console-to-code feature in action! 

**Step 1:** Login to your AWS management console and navigate to EC2 service

Ensure you choose us-east-1 region (P.S. first limitation) and Lauch EC2 instance. I won't go into details of lauching EC2 instance. You can refer documentation [HERE](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance) 

**Step 2:** You will find new option in left panel "Console-to-Code". Click that.
![console-to-code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wa0bil9wgdxmkrlci77s.png)

**Step 3:** Choose Mutating from drop down for Type and click checkbox for actions you would like to include in your code.

![select-actions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lczbkc9sv0xwthkhepys.png)

The options for drop down for Type are "Show all", "Show mutating", and "Show read-only".

Let me show you what you see when you choose "Show all"

![show all actions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3db66ulltf4a3plon5oc.png)

One observation is that, read-only actions flow to console-to-code page right away but mutating actions take few minutes. So be patient. I've repeated steps once, thinking the feature didn't work somehow :-). Anyway, let AWS take it's time to get all the actions in console-to-code page.

**Step 4:** Once you select action, "Generate {code} code" will be clickable. Choose your choice of code format from drop down.

![choose YAML](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyi8qpwt2hi864p1it30.png)

Here you go, your code template is ready. You can copy or download the code.

![final code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsvbc8mqc1pkzvudg9o9.png)

**Step 5:** Use the code as a starting point for your infrastructure-as-code. You'll need to customize the code to make it production-ready for your specific use case.

Please note that only actions taken during the current session are listed. Actions taken during previous sessions are not retained. Also you can choose only 5 actions at a time. 
[P.S. Second limitation]

Let's understand limitations of Console-to-Code feature of EC2.

* Currently only region supported is US East (N. Virginia).
* Supported code formats
```
- CDK Java
- CDK Python
- CDK TypeScript
- CloudFormation JSON
- CloudFormation YAML 

```
* You can only choose 5 actions to include in your code file.

I have to make changes to make the code usable, so it's not perfect, but it's definitely a promising start to put generative AI capabilities to work. I hope the tool improves as people start using it and provide feedback to AWS. I also wish Console-to-Code will not be restricted to EC2 alone. Anyway it will be interesting to see how this feature evolves.

Check AWS feature annoucement [HERE](https://aws.amazon.com/about-aws/whats-new/2023/11/aws-console-to-code-preview-generate-console-actions/) and AWS documentation [HERE](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/console-to-code.html).

If you prefer video tutorial, please refer
{% embed https://youtu.be/HZnouzYMQmE %}