Resources used
Amazon Elasticache| Redis | EC2
Steps
Step 1: Create AWS Redis cluster
Step 3: Connect Redis cluster with EC2 Instance
Flow Diagram
When a user accesses a web application deployed on an Amazon EC2 instance that uses Redis, the workflow generally involves several components working together. Here’s a simplified explanation of the workflow:
User Accesses the Web Application:
The user opens a web browser and enters the URL of the web application hosted on the Amazon EC2 instance.
Amazon EC2 Instance (Web Server):
The web server running on the EC2 instance processes the user’s request.
It may generate dynamic content, interact with databases, and handle business logic.
Interaction with Redis:
If the web application uses Redis, it might be for various purposes, such as caching, session storage, or storing temporary data.
The web server communicates with the Redis server to read or write data.
Caching (Example Use Case):
If Redis is used for caching, the web server checks if the requested data is already present in the Redis cache.
If the data is found in the cache, the web server retrieves it from Redis, avoiding the need to perform more resource-intensive operations (such as querying a database).
Database Interaction (Optional):
If the requested data is not in the Redis cache, or if Redis is not used for caching, the web server may interact with a database to fetch the required information.
Response to the User:
The web server processes the request, possibly combining data from Redis and/or a database.
It generates an HTML page or another type of response.
Web Application Response:
The web server sends the response back to the user’s browser.
User Sees the Result:
The user’s browser receives and renders the response, and the user interacts with the web application.
In summary, the EC2 instance hosts the web application, which interacts with Redis for data storage or caching. The use of Redis can improve performance by reducing the need to repeatedly query databases for the same data, especially if the web application experiences a high volume of requests.
Step 1: Create AWS Redis cluster
All services >> Elasti cache >> Resources >> Redis clusters >> create
All services >> EC2 >> Create instance
Choose Amazon Linux 2 OS image not Amazon Linux
Step 3: Connect Redis cluster with EC2 Instance
1)Connect to EC2 Instance with SSH from local machine
RUN:
ssh -i "new.pem" ec2-user@ec2-54-166-218-161.compute-1.amazonaws.com
#In the Instance
sudo su #root user
sudo amazon-linux-extras install
sudo amazon-linux-extras install epel
sudo yum update
sudo yum install redis
redis-cli –-version
2)Goto redis cluster created :
Copy the primary endpoint without port number — that should look like this —– redisdemo.r2l1h1.ng.0001.use1.cache.amazonaws.com
Now RUN:
redis-cli -h redisdemo.r2l1h1.ng.0001.use1.cache.amazonaws.com -p 6379
By executing the above command you will be into the redis cluster from the ec2-instance.
Now, your Redis cluster is connected with the ec2-instance, in case you are having issues, revisit the security group and enable/open ports required.
Thanks for going through the document, please