This tutorial will guide you that how to create, granting access to, connect to, and finally delete a Redis (cluster mode disabled) cluster using the ElastiCache Management Console
Amazon ElastiCache supports high availability through the use of Redis replication groups.
Starting with Redis version 5.0.5, ElastiCache Redis supports partitioning your data across multiple node groups, with each node group implementing a replication group. This tutorial creates a standalone Redis cluster.
Determine Requirements
Setting Up
Step 1: Launch a Cluster
#Step 2: Authorize Access
Step 3: Connect to a Cluster’s Node
#Step 4: Delete Your Cluster (To avoid Unnecessary Charges)
Before you create a Redis cluster or replication group, you should always determine the requirements for a cluster or replication group so that when you create it, it will meet your business needs and not need to be redone. Because in this exercise we will largely accept default values for the cluster, we will dispense with determining requirements.
Following, you can find topics that describe the one-time actions you must take to start using an ElastiCache.
Create Your AWS Account
Set Up Your Permissions (New an ElastiCache Users Only)
To use an Amazon ElastiCache, you must have an active AWS account and permissions to access ElastiCache and other AWS resources.
If you don’t already have an AWS account, create one now. AWS accounts are free. You will not charge for signing up for an AWS service, only for using AWS services.
Amazon ElastiCache creates & uses service-linked roles to provision resources and access other AWS resources and services on your behalf. For ElastiCache to create a service-linked role for the user, use the AWS-managed policy named AmazonElastiCacheFullAccess. This role comes pre-provisioned with permission that the service to create a service-linked role on your behalf.
You might decide not to use the default policy and instead to use a custom-managed policy. In this case, make sure that you have either permissions to call iam:createServiceLinkedRole or that you have created an ElastiCache service-linked role.
Creating a New Policy (IAM)
AWS-Managed (Predefined) Policies for Amazon ElastiCache
Using Service-Linked Roles for Amazon ElastiCache
The cluster you’re about to launch will be live, and not running in the sandbox. You will incur the standard ElastiCache usage fees for the instance until you delete the cluster. The total charges will be minimum (typically less than a dollar) if you complete the exercise described herein one sitting and delete your cluster when you are finished.
Your cluster is launched in an Amazon VPC. Before you start creating your cluster, you need to create a subnet group for the cluster.
To create a standalone Redis (cluster mode disabled/single node) cluster
If you already have an available cluster, select Launch Cluster.
Must contain 1 to 40 alphanumeric characters or hyphens.
Must begin with a letter.
It can’t contain two consecutive hyphens.
Can’t end with a hyphen.
From the Engine version compatibility list, choose the Redis engine version you want to run on this cluster. Unless you have a specific reason to run an older version, we recommend that you choose the latest version.
In Port, accept the default port, 6379. If you have a reason to use a different port, enter the port number.
When you select None, the Replication group description field disappears.
The Advanced Redis cluster settings details are slightly different if you are creating a Redis (cluster mode enabled) replication group.
From the Subnet group list, select the subnet you want to apply to this cluster. For this exercise, choose default.
For this exercise, select Specify availability zones and then choose an Availability Zone from the list below Primary.
This section considers that you are familiar with launching and connecting to Amazon EC2 instances.
All ElastiCache clusters are designed to be accessed from an Amazon Elastic Compute Cloud (EC2) instance. The most common scenario is to access an ElastiCache cluster from an Amazon Elastic Compute Cloud EC2 instance in the same Amazon Virtual Private Cloud (Amazon VPC). This is the scenario covered in this topic.
The steps required depend upon whether you launched your cluster into EC2-VPC or EC2-Classic.
Here I choose Amazon Linux 2 AMI under free tier eligible.
Go to EC2 Dashboard choose AMI
Select the type of instance and click NEXT
Choose subnet which you have configured in previous steps for Radis cluster and default vpc.
Now connect using your private key. PPK through Putty.exe (for windows user only)
For Linux/ Mac user doesn’t need putty to connect
Now Ec2 instance is running to use for Redis cluster
Redis engine port number is 6379 and to run Redis cluster properly
Set it in the inbound rule under a security group of Redis cluster
Step 3: Connect to a Cluster’s Node
To connect Redis cluster you have to Authorize Access.
This section considers that you’ve created an Amazon EC2 instance and can connect to it.
An Amazon EC2 instance can connect to a cluster node only if you have authorized it in the previous step
When your cluster is in the available state and you’ve authorized access to it (Step 2: Authorize Access), you can log in to an Amazon EC2 instance and connect to the cluster. To do so, you must first find the endpoint.
When you find the endpoint you require, copy it to your clipboard for use in Step 3.2.
Redis (Cluster Mode Disabled) Cluster’s Endpoints (Console): You need the primary endpoint of a replication group or the node endpoint of a standalone node.
Finding Endpoints for a Redis (Cluster Mode Enabled) Cluster (Console): You need the cluster’s Configuration endpoint.
Endpoints (AWS CLI)
Finding Endpoints (ElastiCache API)
Now that you have the endpoint you need, you can log in to an EC2 instance and connect to the cluster or replication group.
In the following example, you use the redis-cli utility to connect to a cluster that is not encryption enabled and running Redis.
To connect to a Redis cluster that is not encryption-enabled using redis-cli utility
At the command prompt of your EC2 instance, type the following command then, at the confirmation prompt.
type y
Doing this produces output similar to the following
Type y
At the command prompt of your EC2 instance, type the following commands:
Then type y and hit Enter
Use redis cli command to ping between EC2 instance and Redis cluster to check the connection
To happen connection, add security group created during redis cluster in the default security group.
For that, you have to modify the cluster
This results in a Redis command prompt similar to the following.
You are now connected to the cluster and can run Redis commands
You can find this on google search for it redis command cheat sheet
Find basic redis command
// Set KEY “test_hello” with a string value and no expiration
// Get value for KEY ” test_hello”
You can append KEY and can list all key available
By using the command KEYS_*
quit // Exit from redis-cli
You can monitor metrics of redis cluster for CPU utilization engine CPU utilization and swap usage, etc
Important
It is almost always a good idea to delete clusters that you are not actively using. Until a cluster’s status is deleted, you continue to incur charges for running clusters.
To delete a cluster
If you choose Delete, the status of the cluster changes to deleting.
As soon as your cluster is no longer listed in the list of clusters, you stop incurring charges for it.
Now you have successfully launched, authorized access to, connected to, viewed, and deleted an ElastiCache for Redis cluster.
# Last but not least, always ask for help!