Table of contents
- Task-01
- Create a Free tier RDS instance of MySQL
- Create an EC2 instance
- Create an IAM role with RDS access
- Assign the role to EC2 so that your EC2 Instance can connect with RDS
- Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client You should install mysql client on EC2, and connect the Host and Port of RDS with this client.
Amazon Relational Database Service (Amazon RDS) is a collection of managed services that makes it simple to set up, operate, and scale databases in the cloud.
Task-01
Create a Free tier RDS instance of MySQL
- Open the AWS Management Console and navigate to the RDS service.
- Click on "Create database" (blue button) and choose "MySQL" as the engine and select a desired latest version.
- Under "Templates," select the "Free tier" option (if available in your region).
- Provide a unique name for your database instance (e.g., "my-mysql-db") and Choose a master username and a strong password for accessing the database.
- Select an appropriate instance class based on your workload (t2.micro for a basic setup).
Pending in RDS...........................⬆️
Create an EC2 instance
- In the RDS > Create database page it-self you can create an instance comes in connectivity. Click on Connect to an EC2 compute resource then Create EC2 instance.
- After that Launch an instance page will open there you can create your instance as you did regularly.
- Now inbound your Mysql security group in your instance.
Continue in RDS...................⬇️
- After instance comes in running state come back to RDS > Create Database page and in connectivity section do refresh and select your instance which you created in the above task
- In Additional VPC security group choose default VPC.
- Rest of them keep it as default and click on create database.
Create an IAM role with RDS access
- Navigate to the IAM service in the AWS Management Console and Click on "Roles" and then "Create role."
- Choose "EC2" under "AWS service" as the trusted entity (service that will use this role) and click on Next.
- Select the appropriate policy for RDS access. A common option is "AmazonRDSFullAccess" which grants full access to RDS resources and click on Next. However, for better security practices, consider using a more granular policy that grants only the necessary permissions for your specific use case.
- Provide a name for your IAM role (e.g., "EC2RDSAccessRole") and Click "Create role" to create the IAM role.
Assign the role to EC2 so that your EC2 Instance can connect with RDS
- Go back to the EC2 service and navigate to the "Instances" section and Select the EC2 instance you launched earlier and Click on "Actions" and then click on "Security" and click on "Modify IAM role".
- After that Modify IAM role page will open in that you have to refresh and do search and select for you IAM role which you created "EC2RDSAccessRole" and click on Update IAM role.
Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client You should install mysql client on EC2, and connect the Host and Port of RDS with this client.
- Use a secure method like SSH to connect to your EC2 instance.
- Once connected, update package lists and install the MySQL client on your EC2 instance using the appropriate package manager for your chosen AMI and get in to super user.
sudo apt-get update && sudo apt-get install mysql-client && sudo su && mysql --version
- Use the MySQL client to connect to the RDS instance. Replace
your-rds-endpoint
with the endpoint of your RDS instance:
End point & Port no(you can see in RDS page which you created):
- Click on RDS which you created and in connectivity & security section you will see end point & Port no.
mysql -h <RDS_HOST> -P <RDS_PORT> -u <USERNAME> -p
show databases;
Happy Learning
Thanks For Reading! :)
-Sri Parthu💝💥