AWS Console-to-Code is transforming the way developers and cloud architects deploy resources by simplifying the transition from manual setups to automated Infrastructure as Code (IaC). This powerful feature records your actions in the AWS Management Console and generates code snippets in AWS CLI, CDK, or CloudFormation formats. It accelerates automation, enhances scalability, and ensures deployments can be replicated efficiently while adhering to best practices. Let’s explore how Console-to-Code can simplify the process of building a two-tier web architecture.
Why Choose Console-to-Code?
Traditionally, setting up cloud resources via the AWS Management Console was time-consuming, error-prone, and cumbersome when migrating from development to production environments. Console-to-Code addresses these challenges by:
- Automating Reuse: Converting manual configurations into reusable IaC templates.
- Providing Flexibility: Generating code in multiple formats (CLI, CDK, CloudFormation).
- Enhancing Accuracy: Ensuring consistent, error-free deployments across environments.
Building a Two-Tier Architecture
Architecture Overview
In this example, we’ll deploy a simple two-tier application using a Virtual Private Cloud (VPC) with:
- Public Subnet: Hosts an EC2 instance for the web application.
- Isolated Subnet: Hosts an Aurora MySQL database for secure data storage.
Console-to-Code simplifies the configuration of route tables and security groups to enable secure communication between the EC2 instance and the RDS database.
Step-by-Step Guide
For each AWS service, select the Console-to-Code button to generate reusable code in your preferred IaC language. Console-to-Code will record your actions and output scripts for future use.
Step 1: Create the VPC
-
Open the VPC Dashboard in the AWS Management Console.
-
Create a new VPC with the CIDR block 10.0.0.0/16.
-
Add the following subnets:
- Public Subnet: 10.0.1.0/24
- Isolated Subnet: 10.0.2.0/24
Step 2: Launch the EC2 Instance
-
Open the EC2 Dashboard.
-
Launch a new EC2 instance with the following settings:
- AMI: Amazon Linux 2023
- Instance Type: t2.micro
- Network: Associate with the public subnet.
- Create and attach a security group to the instance:
- Allow HTTP (port 80) traffic from your IP address.
- Restrict outbound traffic to the database subnet only.
- Assign a public IP address to enable external web access.
Step 3: Set Up Aurora RDS MySQL Database
- to the RDS Dashboard and create a new Aurora MySQL database:
- Choose serverless v2 for scalable workloads.
- Deploy the database in the isolated subnet.
- Create a security group for RDS:
- Allow inbound traffic only from the EC2 instance’s security group on port 3306.
- Deny all other inbound access for enhanced security.
Step 4: Configure Connectivity Between EC2 and RDS
- Update the web application running on the EC2 instance to connect to the Aurora MySQL database using the RDS endpoint.
- Verify the connection by running a test query from the EC2 instance.
Example Generated Code (CDK)
Here’s an example of the CDK script generated by Console-to-Code for this two-tier architecture:
Limitations of Console-to-Code
Currently, Console-to-Code supports generating IaC templates only for VPC, EC2, and RDS services. More services are expected to be added soon. Note that usage limits depend on the tier of service under Amazon Q Developer:
- Free Tier: Unlimited CLI generation but limited CDK/CloudFormation usage per month.
- Pro Tier: No fixed monthly limits for any code generation.
Refer to the Amazon Q Developer documentation for details.
Conclusion
AWS Console-to-Code bridges the gap between manual setups and IaC, enabling even those with limited coding experience to build and deploy scalable architectures effortlessly. With its flexibility, ease of use, and focus on automation, Console-to-Code is an indispensable tool for modern cloud infrastructure management. Try it today and transform your deployment workflows.