AWS DAY 04 Unlocking Scalability and Efficiency with AWS RDS, DynamoDB, and Lambda.
The cloud offers a vast array of tools for building powerful applications. Today, let's explore three essential services from AWS: RDS, DynamoDB, and Lambda, understanding their strengths and how they can work together.π
AWS Relational Database Service (RDS): is a web service which offers a managed relational database service, supporting various database engines like MySQL, PostgreSQL, SQL Server, and more. It handles routine tasks like provisioning, patching, backup, and scaling, allowing you to focus on your application's core functionality. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.
Amazon DynamoDB: DynamoDB is a fully managed NoSQL database service designed for applications that require single-digit millisecond latency at any scale. It offers seamless scalability, consistent performance, and built-in security features, making it an ideal choice for real-time applications with high throughput and low latency requirements.
AWS Lambda: AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. You can upload your code, and Lambda takes care of everything else, including scaling, monitoring, and security. Lambda functions can be triggered by various AWS services or custom events, allowing you to build highly responsive and event-driven applications.
For Example: In the real estate application, you can utilise AWS RDS to manage user profiles and transaction data, DynamoDB to store dynamic property listings, and AWS Lambda for serverless functions like image processing, user authentication, and search queries. For instance, when a user submits a new property listing, a Lambda function triggers, validating the data, processing images, and updating the DynamoDB table with the new listing details. This seamless integration of RDS, DynamoDB, and Lambda ensures a scalable and responsive experience for users searching, exploring, and interacting with real estate listings.
Let's do some hands-on practice on this topics...π©βπ»
What needs to be doneπ:
Set up and configure a MySQL database on AWS RDS, ensuring optimal performance.Establish a connection between the RDS instance and your EC2 environment.
Sign in to your AWS console.
Go to the RDS service from the list of available services.
Click on "Create database" to launch the RDS wizard.
Choose "MySQL" as the database engine.
Select the version of MySQL you want to use.
Choose the appropriate instance size based on your requirements, here i am use free tire.
Configure settings like DB instance identifier, master username, password, etc.
- After launching the RDS instance successfully, Select the instance and click on Setup EC2 Connection.Set up the connection and select the running EC2 instance id.
- Review and confirm your EC2, and click on Set Up. And your database instance is connected to EC2 successfully.
- First, you need to install MySQL on EC2 and then connect it using an endpoint. And for the endpoint, go to the dbinstance and click on your db instance in the details view. Copy your db endpoint.
What needs to be doneπ:
Create an AWS Lambda function that will start/stop instances.
- First Go to the AWS console and navigate to IAM. Here, we create policies that require permissions.Click on "Create Policy".
- Then select EC2 service from the drop-down menu..
- Give access based on the requirement, here we can give permission for start and stop instances and cloudwatch log permissions.
- After selecting the permission, click on the Specify ARN and add the *(astric) sign in both the resource region and resource instance.
- Or you can also add JSON format for creating the policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"ec2:Start*",
"ec2:Stop*"
],
"Resource": "*"
}
]
}
- After creating a policy, go to the IAM roles and create a new role for lambda.
- Here attach above EC2 instance policy to the role.
- Review your details and give name of your role and create role
Next, we are going to create a lambda function. For that, navigate to the lambda tab and click on the create function.
Give the function name which you wan to.
Select the Runtime as a python 3.9
Click on "Change default execution role" and choose our previously created IAM Role.
Click on the "create function".
- After creating the lambda function, go to Code and write the below Python code to stop the instance.
- Once write a code click on the test and create a new test event after test click on the deploy the function.
Creating the EventBridge for lambda:
EventBridge is used for Lambda to automatically trigger functions based on events or schedules without manual intervention. It allows you to define rules to invoke Lambda in response to specific events, such as time-based schedules (cron jobs), state changes in AWS services, or custom events, providing a scalable and efficient way to manage event-driven applications.
For creating the event bridge Navigate to EventBridge in the AWS Management Console and click on "Create Rule".
Give a schedule name and keep the default in the schedule group.
Next, you have the schedule pattern option in the occurrence, choose the recurring schedule, and choose the cron-based schedule option.
After that, set your cron based on your requirements. Here is my schedule cron: 05/20 * * * * * * This cron is run daily at 20:05 p.m.
- After that defilne the rule choose the schedule option.
- Select the target as a lambda.
- Select the lambda function which we create above.
- Now Go to your EC2 dashboard and check your cron is running or not.If your cron is not work check the cloudwatch logs for start and stop instace.
Great job on tackling AWS RDS and Lambda setup! Keep up the excellent work!β¨
Conclusion
In conclusion, AWS RDS, DynamoDB, and Lambda offer a trifecta of services that can revolutionize how you store, manage, and process data in the cloud. Whether you're building a scalable web application, a real-time analytics platform, or a serverless architecture, these services provide the flexibility, scalability, and reliability you need to succeed in today's digital landscape. So why wait? Unlock the full potential of AWS and take your applications to new heights...π€
Subscribe to my newsletter
Read articles from Aesha Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by