Ends in
00
days
00
hrs
00
mins
00
secs
SHOP NOW

🚀 25% OFF All Practice Exams, Video Courses, & eBooks – Cyber Sale Extension!

Guided Lab: Creating an Amazon RDS Instance with AWS Console-to-Code

Description

AWS Console-to-Code is a feature that allows AWS users to transform actions performed in the AWS Management Console into reusable code like CLI commands. Console-to-Code can generate IaC templates in several languages and formats, including CDK Java, CDK Python, CDK TypeScript, CloudFormation JSON, and CloudFormation YAML. This feature is useful for creating Infrastructure as Code (IaC) scripts based on manual configurations. By capturing the console actions as code, you can quickly replicate infrastructure setups, automate deployments, and maintain consistency across environments.

In this lab, we’ll use Console-to-Code to record an RDS database instance’s creation and modify the code to create a second database using the AWS CLI.

Prerequisites

This lab assumes you have the following:

  • Basic knowledge and understanding of Amazon RDS and AWS CLI.

If you find any gaps in your knowledge, consider taking the following lab:

Objectives

By the end of this lab, you will:

  • Learn how to use Console-to-Code to capture RDS database creation steps.
  • Understand how to edit and reuse the code for additional resources.
  • Set up and configure an AWS CLI environment to automate RDS database creation.
  • Incorporate a waiting time after creating the database to ensure it’s fully available before verification.

Lab Steps

Record Creating RDS Database Instance Using Console-to-Code

1. Navigate to the Amazon RDS Console.

2.  Open the Console-to-Code feature and Start recording. Then, click Create database

3. Create a Database with the following configuration:

  • Choose a database creation method: Standard create
  • Engine options:
    • Engine type: MySQL
    • Engine Version: Leave it as default
    • Templates: Free tier
    • Settings:
      • DB instance identifier: database-1
      • Master username: admin (you can change this as you desire)
      • Credentials management: Self managed
      • For the simplicity of this lab, we will tick the auto-generate password checkbox.

But take note that in PRODUCTION, you need to create a strong password for the security of your Database

  • Instance configuration:
    • DB instance size:, db.t3.micro
  • Storage:
    • Storage type: General Purpose SSD (gp2)
    • Allocated storage: 20
  • Leave the rest as default and click Create Database

4. Stop the Recording in Console-to-Code to generate code based on your actions.

Copy and Edit the Generated Code

1.  In the Console-to-Code output, view the captured AWS CLI commands.

  • Select the createDBInstance, and click on Copy CLI.

2. Copy the Code and paste it into a text editor.

  • Edit the Code to create a new RDS instance with a different identifier.


Note: The generated code may contain errors or placeholder values that need to be adjusted.

  • Example command template (replace placeholders with your specific values):
aws rds create-db-instance \
    --engine "mysql" \
    --engine-version "8.0.39" \
    --db-instance-identifier "MyRDSInstance2222" \
    --master-username "admin" \
    --db-instance-class "db.t3.micro" \
    --db-subnet-group-name "<YourSubnetGroupName>" \
    --vpc-security-group-ids "<YourSecurityGroupID>" \
    --availability-zone "<YourAvailabilityZone>" \
    --port "3306" \
    --storage-type "gp3" \
    --allocated-storage "20" \
    --db-parameter-group-name "<YourParameterGroupName>" \
    --option-group-name "<YourOptionGroupName>" \
    --processor-features \
    --max-allocated-storage "1000" \
    --ca-certificate-identifier "rds-ca-rsa2048-g1" \
    --master-user-password "<YourMasterPassword>"

Placeholder Descriptions:

  • <YourSubnetGroupName>: Replace with the name of your DB subnet group.
  • <YourSecurityGroupID>: Replace with the ID of the VPC security group.
  • <YourAvailabilityZone>: Replace with the appropriate availability zone (e.g., us-east-1a).
  • <YourParameterGroupName>: Replace with the name of your DB parameter group.
  • <YourOptionGroupName>: Replace with the name of your DB option group.
  • <YourMasterPassword>: Replace with your master user password.

3.  Save the modified code for later use.

Create AWS Access Keys

1. Go to IAM in the AWS Console.

2. Go to Users > Click on your current User name > Security credentials > Create access key.

3. Follow the following configurations:

  • Use case: Select Command Line Interface (CLI)
  • Check on the Confirmation

  • Click on Next
  • Description tag value: myCLIAccessKey
  • Click on Create access key

4. After creating the access key, copy the Access key and Secret access key to your clipboard. You can also download the .csv file of it.

Run the Code to Create the RDS Instance

1. Ensure that the RDS database we created earlier is now in Available Status.

2. Open a terminal on your local machine and configure the AWS CLI:

aws configure
  • Enter your Access Key IDSecret Access Key, preferred AWS region, and output format when prompted.

3. To create the new RDS instance, copy the code from the text editor and paste it into the terminal.

4. Go to the Amazon RDS Console and verify that both MyRDSInstance1111 and MyRDSInstance2222 are listed.

  • Confirm that the configurations (engine type, instance class, storage, connectivity) match the specifications used in the code.

Congratulations! You have successfully automated the creation of an Amazon RDS database instance using Console-to-Code. By capturing manual steps and converting them into code, you could create and automate infrastructure setup, demonstrating how Console-to-Code simplifies the adoption of Infrastructure as Code (IaC).

Key Takeaways:

  • Console-to-Code captures reusable console actions, facilitating the transition to Infrastructure as Code.
  • Automating infrastructure with AWS CLI reduces manual effort and improves repeatability.
  • Editing captured code allows you to modify and deploy similar resources quickly.

As a best practice, remember to delete any resources no longer in use to maintain a clutter-free AWS environment.

Thank you for joining this lab, and happy learning!

Skip to content