Setup Amazon Elasticache for Redis and establish connectivity to EC2.

 Introduction:

Welcome to the blog by The Quick Desk! Today, We will set up the Amazon Elasticache for Redis on AWS and connect to it using the redis-cli. Here we will also learn how to install redis-cli on Amazon Linux 2023 using the latest package manager(dnf) and configuring the security groups even for customs port to establish connectivity to the Amazon Elasticache for Redis. We will do the installation from source, which makes it an easy and more generalized tutorial as these same steps and commands can be used on your local Linux-based machine as well. We will also show you how to use the redis-cli tool to perform basic operations, such as setting and getting values.

What Is Amazon ElastiCache for Redis?

Amazon ElastiCache for Redis is a blazing fast in-memory data store that provides sub-millisecond latency to power internet-scale real-time applications. Built on open-source Redis and compatible with the Redis APIs, ElastiCache for Redis works with your Redis clients and uses the open Redis data format to store your data. Your self-managed Redis applications can work seamlessly with ElastiCache for Redis without any code changes. ElastiCache for Redis combines the speed, simplicity, and versatility of open-source Redis with manageability, security, and scalability from Amazon to power the most demanding real-time applications in Gaming, Ad-Tech, E-Commerce, Healthcare, Financial Services, and IoT.



Prerequisites:

Before we get started, you should have the following:


  1. An AWS account
  2. A basic understanding of AWS services, including EC2 and ElastiCache.
  3. An EC2 instance that you can connect to via SSH.
  4. A Security Group for the Redis Cluster that will allow inbound and outbound traffic on port 6379 (default Redis port).
#We are using 3680 instead of default port, whichever port you use for you Amazon Elasticache redis cluster , that must be allowed in the security group. 

Creating Amazon Elasticache cluster for Redis:

    1. Go to Amazon ElastiCache.
    2. Click on Redis Cluster.



    3. Click on Create Redis Cluster.



    4. Choose "Configure and create a new cluster". For Cluster mode choose "Disabled" as we are doing it for the demo but for larger workloads choose "Enabled".When cluster mode is enabled, data is automatically partitioned across multiple shards or node groups, each with its own primary node and up to 5 read replicas. This enables the system to handle large workloads and provide high availability, even in the event of a node failure.

        #Give the cluster a name for example: redis-clstr-01

    5. For location keep it as AWS Cloud.

    6. In Cluster settings, you can select the engine version, port, and Node type. There are various types of nodes available, you can select them as per the preference of your workload. Here we are selecting cache.t2.micro.

#Redis uses 6379 as the default port, you can choose a custom port by changing here for example we are using 6380.



        For the Number of replicas, you can put up to 5 read replicas under the single primary node.

    7. For Connectivity, you can create a new Subnet group under the VPC here the cluster will run, and you can manage the subnets also in which the nodes will be created.


    8. In Security Tab, you can configure the network and data security of your cluster.                       We are choosing encryption in transit, to demo the TLS encryption connection support in         Cluster.


        Also, you need to add the security group for your Redis Cluster, which must allow inbound and outbound traffic on port 6379 (default Redis port). You can change the port as mentioned in Step 6.



    9. Rest settings are related to backup and maintenance which can be chosen as per the  preference of the workload model. After the Review, Click on Create.





Finally, after successful creation, you can check the details of your Cluster. Copy the Primary Endpoint and Port, from here as these will be used to access the Redis Cluster.





Installation of redis-cli from source.

We are installing redis-cli on Amazon Linux 2023 and will use it for connecting to the Amazon Elasticache Cluster. You can install the redis-cli on your sandbox with similar steps.
👉To install redis-cli on Amazon Linux 2023, we need to first install the necessary packages for compiling:                                                                                                                                           
 sudo dnf groupinstall "Development Tools"                                                                   
 sudo dnf install openssl-devel         

👉Next, we need to download the Redis source code.                                                                     
 wget https://download.redis.io/redis-stable.tar.gz     

👉To unzip the tar.gz use :                                                                                                                     
 tar -xzvf redis-stable.tar.gz       

👉Go to the directory "redis-stable"                                                                                                   
 cd redis-stable     

👉Install it with TLS support :                                                                                                               
 sudo make BUILD_TLS=yes                                                                                           
 make install

👉After installation, we can connect to the ElastiCache for the Redis cluster using the redis-cli tool:     
 redis-cli -h <cluster-endpoint> -a <auth-token> --tls -p <port-number>

In conclusion, By following the steps outlined in this blog post, you should now be able to set up Amazon ElastiCache for Redis and establish connectivity to an EC2 instance using redis-cli. For the video tutorial, you can check out the video below:


If you have any questions or comments, please feel free to leave them below. And don't forget to like, comment, and subscribe to our channel The Quick Desk for more helpful videos and blog posts!


Comments

Popular posts from this blog

Deploying Angular Web App on Amazon EC2 with AL2023 and Nginx

Setting up MariaDB on Ubuntu EC2 instance & configure remote access.