Setting up ElastiCache
To use the ElastiCache web service, follow these steps.
Topics
Sign up for an Amazon Web Services account
If you do not have an Amazon Web Services account, use the following procedure to create one.
To sign up for Amazon Web Services
Open http://www.amazonaws.cn/
and choose Sign Up. Follow the on-screen instructions.
Amazon sends you a confirmation email after the sign-up process is
complete. At any time, you can view your current account activity and manage your account by
going to http://www.amazonaws.cn/
Secure IAM users
After you sign up for an Amazon Web Services account, safeguard your administrative user by turning on multi-factor authentication (MFA). For instructions, see Enable a virtual MFA device for an IAM user (console) in the IAM User Guide.
To give other users access to your Amazon Web Services account resources, create IAM users. To secure your IAM users, turn on MFA and only give the IAM users the permissions needed to perform their tasks.
For more information about creating and securing IAM users, see the following topics in the IAM User Guide:
Grant programmatic access
Users need programmatic access if they want to interact with Amazon outside of the Amazon Web Services Management Console. The Amazon APIs and the Amazon Command Line Interface require access keys. Whenever possible, create temporary credentials that consist of an access key ID, a secret access key, and a security token that indicates when the credentials expire.
To grant users programmatic access, choose one of the following options.
Which user needs programmatic access? | To | By |
---|---|---|
IAM | Use short-term credentials to sign programmatic requests to the Amazon CLI or Amazon APIs (directly or by using the Amazon SDKs). | Following the instructions in Using temporary credentials with Amazon resources in the IAM User Guide. |
IAM | (Not recommended) Use long-term credentials to sign programmatic requests to the Amazon CLI or Amazon APIs (directly or by using the Amazon SDKs). |
Following the instructions in Managing access keys for IAM users in the IAM User Guide. |
Related topics:
What is IAM in the IAM User Guide.
Amazon Security Credentials in Amazon General Reference.
Set up your permissions (new ElastiCache users only)
To provide access, add permissions to your users, groups, or roles:
-
Users managed in IAM through an identity provider:
Create a role for identity federation. Follow the instructions in Create a role for a third-party identity provider (federation) in the IAM User Guide.
-
IAM users:
-
Create a role that your user can assume. Follow the instructions in Create a role for an IAM user in the IAM User Guide.
-
(Not recommended) Attach a policy directly to a user or add a user to a user group. Follow the instructions in Adding permissions to a user (console) in the IAM User Guide.
-
Amazon ElastiCache creates and uses service-linked roles to provision resources and access other
Amazon resources and services on your behalf. For ElastiCache to create a service-linked role
for you, use the Amazon-managed policy named AmazonElastiCacheFullAccess
. This
role comes preprovisioned with permission that the service requires 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 the ElastiCache
service-linked role.
For more information, see the following:
Set up EC2
You will need to setup an EC2 instance from which you will connect to your cache.
If you don’t already have an EC2 instance, learn how to setup an EC2 instance here: Amazon EC2 Getting Started Guide.
Your EC2 instance must be in the same VPC and have the same security group settings as your cache. By default, Amazon ElastiCache creates a cache in your default VPC and uses the default security group. To follow this tutorial, ensure that your EC2 instance is in the default VPC and has the default security group.
Grant network access from an Amazon VPC security group to your cache
ElastiCache self-designed clusters use port 6379 for Valkey and Redis OSS commands, and ElastiCache serverless uses both port 6379 and port 6380. In order to successfully connect and execute Valkey or Redis OSS commands from your EC2 instance, your security group must allow access to these ports as needed.
ElastiCache for Memcached uses the 11211 and 11212 ports to accept Memcached commands. In order to successfully connect and execute Memcached commands from your EC2 instance, your security group must allow access to these ports.
Sign in to the Amazon Command Line Interface and open the Amazon EC2 console
. In the navigation pane, under Network & Security, choose Security Groups.
From the list of security groups, choose the security group for your Amazon VPC. Unless you created a security group for ElastiCache use, this security group will be named default.
Choose the Inbound tab, and then:
-
Choose Edit.
-
Choose Add rule.
-
In the Type column, choose Custom TCP rule.
-
If using Valkey or Redis OSS, then in the Port range box, type
6379
.If using Memcached, then in the Port range box, type
11211
. -
In the Source box, choose Anywhere which has the port range (0.0.0.0/0) so that any Amazon EC2 instance that you launch within your Amazon VPC can connect to your cache.
-
If you are using ElastiCache serverless, add another rule by choosing Add rule.
-
In the Type column, choose Custom TCP rule.
-
If using ElastiCache for Redis OSS, then in the Port rangebox, type
6380
.If using ElastiCache for Memcached, then in the Port rangebox, type
11212
. -
In the Source box, choose Anywhere which has the port range (0.0.0.0/0) so that any Amazon EC2 instance that you launch within your Amazon VPC can connect to your cache.
-
Choose Save
-
Download and set up command line access
Download and install the valkey-cli utility.
If you use ElastiCache for Valkey, then you might find the valkey-cli utility useful. If you're using ElastiCache for Redis OSS with redis-cli, consider switching to valkey-cli as it works for Redis OSS as well.
Connect to your Amazon EC2 instance using the connection utility of your choice. For instructions on how to connect to an Amazon EC2 instance, see the Amazon EC2 Getting Started Guide.
Download and install valkey-cli utility by running the appropriate command for your setup.
Amazon Linux 2
sudo amazon-linux-extras install epel -y sudo yum install gcc jemalloc-devel openssl-devel tcl tcl-devel -y wget https://github.com/valkey-io/valkey/archive/refs/tags/8.0.0.tar.gz tar xvzf 8.0.0.tar.gz cd valkey-8.0.0 make BUILD_TLS=yes
Note
-
When you install the redis6 package, it installs redis6-cli with default encryption support.
-
It is important to have build support for TLS when installing valkey-cli or redis-cli. ElastiCache Serverless is only accessible when TLS is enabled.
-
If you are connecting to a cluster that isn't encrypted, you don't need the
Build_TLS=yes
option.