dₐy ₀₄ ₐws zₑᵣₒ tₒ ₕₑᵣₒ

dₐy ₀₄ ₐws zₑᵣₒ tₒ ₕₑᵣₒ

AWS RDS, DynamoDB and AWS lambda

Image description

Amazon Web Services (AWS) provides a suite of cloud computing services that cater to various business needs. Among these services, Amazon RDS (Relational Database Service), Amazon DynamoDB, and AWS Lambda are key components that play crucial roles in building scalable, flexible, and efficient cloud-based applications.

Amazon RDS (Relational Database Service):

Overview: Amazon RDS is a managed relational database service that makes it easier to set up, operate, and scale a relational database in the cloud. It supports several database engines, including MySQL, PostgreSQL, Oracle, Microsoft SQL Server, and Amazon Aurora.

Key Features:

  1. Managed Service: AWS RDS takes care of routine database tasks such as backups, patch management, and scaling, allowing developers to focus more on application development.

  2. Multi-AZ Deployments: RDS supports Multi-AZ (Availability Zone) deployments for high availability and automatic failover. This ensures that if one AZ becomes unavailable, the system automatically redirects to another AZ.

  3. Security: RDS provides features such as encryption at rest and in transit, network isolation using Amazon VPC, and IAM integration for fine-grained access control.

  4. Scalability: With features like Read Replicas and Aurora Auto-Scaling, RDS enables users to scale their database horizontally and vertically based on the application's needs.

Amazon DynamoDB:

Overview: DynamoDB is a fully managed NoSQL database service provided by AWS. It is designed to provide low-latency and seamless scalability for applications with variable and unpredictable workloads.

Key Features:

  1. Managed NoSQL: DynamoDB is a fully managed NoSQL database that eliminates the administrative overhead of operating and scaling a distributed database.

  2. Scalability: It can scale both read and write capacity independently, allowing applications to handle varying workloads with ease.

  3. Performance: DynamoDB provides single-digit millisecond latency for read and write operations, making it suitable for applications that require low-latency access to data.

  4. Serverless Integration: DynamoDB integrates seamlessly with AWS Lambda, allowing developers to build serverless applications with a fully managed backend.

AWS Lambda:

Overview: AWS Lambda is a serverless computing service that enables developers to run code without provisioning or managing servers. It automatically scales and manages the infrastructure needed to run applications, allowing developers to focus on writing code.

Key Features:

  1. Event-Driven Programming: Lambda functions are triggered by events such as changes to data in an Amazon S3 bucket, updates to an Amazon DynamoDB table, or an HTTP request through Amazon API Gateway.

  2. Pay-Per-Use Pricing: With Lambda, you pay only for the compute time that you consume. There are no upfront costs, and you don't have to pay for idle compute capacity.

  3. Integration with AWS Services: Lambda seamlessly integrates with various AWS services, including RDS and DynamoDB. This integration enables developers to build powerful and scalable applications by combining the strengths of different AWS services.

  4. Multi-Language Support: Lambda supports multiple programming languages, allowing developers to use their preferred language to write functions.

Integration of RDS, DynamoDB, and Lambda:

Developers often use a combination of RDS, DynamoDB, and Lambda to build scalable and cost-effective applications. For example, Lambda functions can be triggered by events from DynamoDB tables or can interact with RDS databases to perform specific tasks. This serverless architecture enables developers to build applications that automatically scale based on demand, without the need to manage the underlying infrastructure.

Tasks:

1) Read about AWS RDS, DynamoDB and AWS lambda and write a post on linkedIn with example in your own words.

Note: I have added documentation for reference below

2) You are part of a team responsible for migrating the database of an existing e-commerce platform to Amazon RDS. The goal is to improve scalability, performance, and manageability. The current setup uses a self-managed MySQL database on an on-premises server. 👇

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

3) Deploy a scalable web application. The application consists of a MySQL database managed by Amazon RDS and a flask based web application that automatically scale based on demand using an Auto Scaling group and an Elastic Load Balancer.

4) Scenario:

You're an AWS expert managing a budget-friendly project with EC2 instances. To save money, you're using AWS Lambda to automatically start and stop instances when they're not needed during non-business hours. 👇

What needs to be done:

  • Create an AWS Lambda function that will start/stop instances based on their instance tag.

TASK 2 :

1)Set up and configure a MySQL database on AWS RDS, ensuring optimal performance.

2)Establish a connection between the RDS instance and your EC2 environment.

MySQL on Amazon RDS

Configuring Amazon RDS:

  1. Database Instance Creation: Navigate to the AWS Management Console, select Amazon RDS, and create a new database instance. Choose MySQL as the engine.

  2. Instance Settings: Define your instance details, including DB credentials, storage, and network configurations.

Connecting EC2 to RDS:

Go to your RDS database. Scroll to the "Connected compute resources" section --> click on 'Actions' -->'Set up EC2connection' and add your ec2 instance( ex: webserver1-ec2).

TASK 3 :

Deploy a scalable web application.

The application consists of a MySQL database managed by Amazon RDS and a flask based web application that automatically scale based on demand using an Auto Scaling group and an Elastic Load Balancer.

Step 1: Creation of a webserver

1)Created launch template.

2)Created Auto sacling group with desired capacity -1,min capacity-1,max.capacity-2.

3)created an Application loadbalancer with a target group(webserver-targetgp)

Now, an instance for our flask app is created with high availabilty and scalability.

Step 2:Dockerization of Web Application

  1. Cloning the Repository: Clone this repository which contains the Dockerfile.

  2. Image Creation: Execute docker build to create an image from your Dockerfile. This encapsulates your app and its dependencies.

Step 3:

  • In your instance terminal, run the following commands.navigate to the RDS homepage, select the database you have already created (named "database-1"), copy the endpoint, and paste it here.
     # Install mysql client
   sudo apt update
   sudo apt install mysql-client

   # Connecting your ec2 instance to the rds database.
   mysql -u admin -h <endpoint> -P 3306 -p
  • Then,enter the password.Now we can see the mysql monitor and run the following commands for creating a new database.
create database db1;
#select db1
use db1;


#create the table
   CREATE TABLE messages (
       id INT AUTO_INCREMENT PRIMARY KEY,
       message TEXT
   );

Step4:Deployment

  1. Running the docker container: Run the docker container using the following command.
   sudo docker run -d -p 5000:5000 -e MYSQL_HOST=<endpoint> -e MYSQL_USER=admin -e MYSQL_PASSWORD=admin123 -e MYSQL_DB=db1 two-tier

Step 5:Check the result

Check the url on your browser http://<ec2-public-ip>:5000.

Now,you can see that our Two-tier flsakapp is unning successfully.

TASK 4 - Scenario:

You're an AWS expert managing a budget-friendly project with EC2 instances. To save money, you're using AWS Lambda to automatically start and stop instances when they're not needed during non-business hours.

What needs to be done:

Create an AWS Lambda function that will start/stop instances based on their instance tag.

Solution:

For this task, I am demonstrating how to stop an instance using AWS Lambda. For reference, please watch this document.AWS LAMBDA

Step1: Create an ec2 instance.

Step2: create IAM policy

Use the JSON policy editor to create an IAM policy. Paste the following JSON policy document into the policy editor.(refer the above doc)

Step3: Create IAM role for Lambda

Important: When you attach a permissions policy to Lambda, make sure that you choose the IAM policy.

Step 4: Create Lambda function

  1. Open the Lambda console, and then choose Create function.

  2. On the Code tab, under Code source, paste the following code for stopping instances (refer AWS LAMBDA).

  3. Replace us-west-1 with the AWS Region that your instances are in. Replace InstanceIds with the IDs of the instances that you want to stop and start.

Step 5:Test your Lambda functions

In the Code source section, choose Test.Enter an Event name. Then, choose Create.
Choose Test to run the function.

Now, go back to your instances page and check the status of the mentioned instance; yes, it's stopped. You can also start/stop instances automatically by using a Lambda function with EventBridge rules.