# Day #44: Relational Database Service in AWS

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
    
* 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.
    

* Create a Free tier RDS instance of MySQL
    
    1. Navigate to the RDS section in the AWS management console and click to Create a database.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681968076005/49bd9a74-d484-4bd1-bd5e-246237819c42.png?auto=compress,format&format=webp align="left")
        
    2. Select the Engine option which is the type of database to setup. We will select MySQL as per our task.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681986986393/330967bf-2b28-4da7-bd98-8dee3bf05f91.png?auto=compress,format&format=webp align="left")
        
    3. Select free-tier as the template.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987063621/b5e4bdc3-1a56-456d-9c1d-3611e1769480.png?auto=compress,format&format=webp align="left")
        
    4. Set up the DB credentials.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987239252/155ecd6d-4df8-44a3-bed4-80887626c5fa.png?auto=compress,format&format=webp align="left")
        
    5. select the db size.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987343656/e58a0d7b-6d11-4ada-80c2-2694ac917234.png?auto=compress,format&format=webp align="left")
        
    6. Select the EC2 Compute connect as we are going to access our database from EC2.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987728416/5096e1b4-5594-4780-90aa-db1622554929.png?auto=compress,format&format=webp align="left")
        
    7. Choose the VPC that you have created already while spinning EC2 instance.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987831011/01084d4b-2072-4e92-aea4-eb4323f4145b.png?auto=compress,format&format=webp align="left")
        
    8. Use Password authentication to access the database.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681987871982/6250608f-09e6-435c-8884-08fd693fda2e.png?auto=compress,format&format=webp align="left")
        
    9. Now the new database is spun up.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681989345751/04fb6acb-d45e-4300-9b46-caf9338198eb.png?auto=compress,format&format=webp align="left")
        
* Create an EC2 instance
    
    1. An instance is created and attached to the database in the above step.
        
* Create an IAM role with RDS access
    
    1. Create a role in IAM.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681989613617/a280c8a5-238b-40df-a972-b1422fe041e1.png?auto=compress,format&format=webp align="left")
        
    2. Select the EC2 option.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681989639739/93ae15ad-9597-4b0d-a0f4-c256bbe0314a.png?auto=compress,format&format=webp align="left")
        
    3. Add RDS full access to the group.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990103536/4c9ff592-9d0d-4f14-be2d-94e7b9aa0904.png?auto=compress,format&format=webp align="left")
        
    4. Provide the role name and create the role now.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990157469/490fa7b5-2f7b-487d-a102-72302e3d2a28.png?auto=compress,format&format=webp align="left")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990312568/db8fbfe9-a1c9-4b8b-8783-def6261e738c.png?auto=compress,format&format=webp align="left")
        
* Assign the role to EC2 so that your EC2 Instance can connect with RDS
    
    1. Navigate to your EC2 instance security settings and modify the IAM role.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990396938/f5016b2d-3982-471f-91e8-cdbf328b0110.png?auto=compress,format&format=webp align="left")
        
    2. Choose your created role to assign to EC2
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990421533/ce1fe434-10f2-453a-bd62-5abc46cceb07.png?auto=compress,format&format=webp align="left")
        
* Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
    
    1. Now navigate to your database and make note of Endpoint that is needed to connect RDS to EC2.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681990569551/55bd90de-304c-4d22-819f-fe5cd8698016.png?auto=compress,format&format=webp align="left")
        
    2. Install MySQL client on EC2.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681991044590/8b7c2cdb-2226-4997-8477-29beced88494.png?auto=compress,format&format=webp align="left")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681991074126/febe7849-e754-4870-b5af-6fbf4eaf3a80.png?auto=compress,format&format=webp align="left")
        
    3. Database will be using 3306 port which you can open in the inbound rule of Instance.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681991163090/aaeb0434-2ea5-4d09-8841-d92109fc6d15.png?auto=compress,format&format=webp align="left")
        
    4. Use the below command to connect to the RDS. You can see now SQL is connected.
        
        **COPY**
        
        **COPY**
        
        ```plaintext
         mysql -h <enpointURL> -P <portno.> -u <username> -p
        ```
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681991349662/e6ce0c0b-178c-49f8-8d40-84e46ff1a2a2.png?auto=compress,format&format=webp align="left")
