Amazon RDS - Hands On Demo​

Step 1: Create an EC2 instance

 

To create an EC2 instance

  1. Sign in to the AWS Management Console and open the Amazon EC2 console.

  2. In the upper-right corner of the AWS Management Console, choose the AWS Region in which you want to create the EC2 instance.

  3. Choose EC2 Dashboard, and then choose Launch instance.

  4. The Launch an instance page opens.

  5. Choose the following settings on the Launch an instance page.

    1. Under Name and tags, for Name, enter ec2-database-connect.

    2. Under Application and OS Images (Amazon Machine Image), choose Amazon Linux, and then choose the Amazon Linux 2023 AMI. Keep the default selections for the other choices.

    3. Under Instance type, choose t2.micro.

    4. Under Key pair (login), choose a Key pair name to use an existing key pair. To create a new key pair for the Amazon EC2 instance, choose Create new key pair and then use the Create key pair window to create it.

    5. For Allow SSH traffic in Network settings, choose the source of SSH connections to the EC2 instance.

    6. Leave the default values for the remaining sections.

    7. Review a summary of your EC2 instance configuration in the Summary panel, and when you're ready, choose Launch instance.
  6. On the Launch Status page, note the identifier for your new EC2 instance.
  7. Choose the EC2 instance identifier to open the list of EC2 instances, and then select your EC2 instance.
  8. In the Details tab, note the following values, which you need when you connect using SSH:

    1. In Instance summary, note the value for Public IPv4 DNS.

    2. In Instance details, note the value for Key pair name.

  9. Wait until the Instance state for your EC2 instance has a status of Running before continuing.

ec2-database-connect

Step 2: Create a PostgreSQL DB instance

 

  1. Sign in to the AWS Management Console and open the Amazon RDS console.

  2. In the upper-right corner of the Amazon RDS console, choose the AWS Region in which you want to create the DB instance.

  3. In the navigation pane, choose Databases.

  4. Choose Create database and make sure that Easy create is chosen.

  5. In Configuration, choose PostgreSQL.

  6. For DB instance size, choose Free tier.

  7. For DB instance identifier, enter database-test1.

  8. For Master username, enter a name for the master user, or keep the default name (postgres).

  9. To use an automatically generated master password for the DB instance, select Auto generate a password.

    To enter your master password, make sure Auto generate a password is cleared, and then enter the same password in Master password and Confirm password.

  10. To set up a connection with the EC2 instance you created previously, open Set up EC2 connection - optional.

    Select Connect to an EC2 compute resource. Choose the EC2 instance you created previously.

  11. Open View default settings for Easy create.

    You can examine the default settings used with Easy create. The Editable after database is created column shows which options you can change after you create the database

  12. Choose Create database.

    To view the master username and password for the DB instance, choose View credential details.

    You can use the username and password that appears to connect to the DB instance as the master user.

database-test1

Step 3: Connect to a PostgreSQL DB instance

 

  1. Find the endpoint (DNS name) and port number for your DB instance.

  2. Choose the PostgreSQL DB instance name to display its details.

  3. On the Connectivity & security tab, copy the endpoint. Also note the port number. You need both the endpoint and the port number to connect to the DB instance.

  4. Connect to your Linux instance with EC2 Instance Connect.

  5. After connecting to EC2 Instance, install postgresql client and connect to postgresql database.

sudo dnf update -y
sudo dnf install postgresql15
psql --host=endpoint --port=5432 --dbname=postgres --username=postgres
SELECT CURRENT_TIMESTAMP;

Step 4: Delete the EC2 instance and DB instance

 

To delete the EC2 instance

  1. Select the EC2 instance, and choose Instance state, Terminate instance.

  2. Choose Terminate when prompted for confirmation.

 

 

To delete a DB instance with no final DB snapshot

  1. Choose the DB instance that you want to delete.

  2. For Actions, choose Delete.

  3. Clear Create final snapshot? and Retain automated backups.

  4. Complete the acknowledgement and choose Delete.

Thanks

For

Watching