DevOps, Day - 44

DevOps, Day - 44

Relational Database Service in AWS

Step 1: Create a Free Tier RDS instance of MySQL

  1. Log in to your AWS Management Console.

  2. Navigate to the RDS service.

    • Click on "Services" in the top-left corner.

    • Under "Database," select "RDS."

  3. Click the "Create database" button.

  4. Choose "Standard Create" to have more control over your RDS instance.

  5. Select the MySQL database engine.

  6. Under "Templates," choose the "Free tier."

  7. Configure your database instance:

    • Settings:

      • DB instance identifier: Provide a unique name for your RDS instance.

      • Master username: Choose a username for your database.

      • Master password: Choose a strong password for the database.

    • DB instance size: Select the "Burstable classes" for the Free tier.

    • Storage: Keep the default storage settings for the Free tier.

    • Connectivity:

      • Launch an EC2 instance

      • VPC: Select the VPC where your EC2 instance will be running.

      • Subnet group: Choose a subnet group that includes the subnets where your EC2 instance can connect.

  8. Review your settings and click "Create database."

  9. Wait for your RDS instance to be created. Once it's available, you can proceed to the next task.


Step 2: Use the Existing EC2 Instance, which was created in step 1.


Step 3: Create an IAM Role with RDS Access

  1. Navigate to the IAM service:

    • Click on "Services" in the top-left corner.

    • Under "Security, Identity, & Compliance," select "IAM."

  2. In the left-hand menu, choose "Roles."

  3. Click the "Create role" button.

  4. Select the use case for the role:

    • AWS service: EC2

  5. Attach permissions policies:

    • In the search box, type "AmazonRDSFullAccess" and select the policy that provides access to RDS.

    • Proceed to the next step, adding any optional tags or review details.

  6. Give your role a name and description, then create the role.

  7. Our role is created.


Step 4: Assign the Role to the Existing EC2 Instance

  1. While still in the IAM console, select the EC2 instance that you created in Task 1.

  2. In the "Actions" tab, click "Security" --> "Modify IAM role"

  3. Search for the policy you created in Task 3, select it, and attach it to your existing EC2 instance. This will grant your EC2 instance permissions to access the RDS instance.


Step 5: Connect Your Existing EC2 Instance to the RDS Instance

  1. SSH into your existing EC2 instance using the key pair you created when launching the instance in Task 1.

  2. Install a MySQL client on your EC2 instance if it's not already installed.

     sudo apt install mysql-client
    
  3. Use the MySQL client to connect to your RDS instance by providing the RDS endpoint, master username, and password:

     mysql -h RDS_ENDPOINT -u MASTER_USERNAME -p
    

    For RDS_ENDPOINT

    • Goto RDS databases --> Click the database you created.

    • Down in Connectivity & Security, we can see our RDS_ENDPOINT

Replace RDS_ENDPOINT with the actual endpoint of your RDS instance, and MASTER_USERNAME with the username you specified when creating the RDS instance. You'll be prompted to enter the password.


Thank you so much for reading

Follow me on LinkedIn to see interesting posts like this : )

Linkedin

Β