Step 3: Connect to the cluster - Amazon MemoryDB for Redis
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Step 3: Connect to the cluster

Before you continue, complete Step 2: Authorize access to the cluster.

This section assumes that you've created an Amazon EC2 instance and can connect to it. For instructions on how to do this, see the Amazon EC2 Getting Started Guide.

An Amazon EC2 instance can connect to a cluster only if you have authorized it to do so.

Find your cluster endpoint

When your cluster is in the available state and you've authorized access to it, you can log in to an Amazon EC2 instance and connect to the cluster. To do so, you must first determine the endpoint.

To further explore how to find your endpoints, see the following:

Connect to a MemoryDB cluster (Linux)

Now that you have the endpoint you need, you can log in to an EC2 instance and connect to the cluster. In the following example, you use the cli utility to connect to a cluster using Ubuntu 22. The latest version of cli also supports SSL/TLS for connecting encryption/authentication enabled clusters.

Connecting to MemoryDB nodes using redis-cli

To access data from MemoryDB nodes, you use clients that work with Secure Socket Layer (SSL). You can also use redis-cli with TLS/SSL on Amazon Linux and Amazon Linux 2.

To use redis-cli to connect to a MemoryDB cluster on Amazon Linux 2 or Amazon Linux
  1. Download and compile the redis-cli utility. This utility is included in the Redis software distribution.

  2. At the command prompt of your EC2 instance, type the appropriate commands for the version of Linux you are using.

    Amazon Linux 2023

    If using Amazon Linux 2023, enter this:

    sudo yum install redis6 -y

    Then type the following command, substituting the endpoint of your cluster and port for what is shown in this example.

    redis-cli -h Primary or Configuration Endpoint --tls -p 6379

    For more information on finding the endpoint, see Find your Node Endpoints.

    Amazon Linux 2

    If using Amazon Linux 2, enter this:

    sudo yum -y install openssl-devel gcc wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make distclean make redis-cli BUILD_TLS=yes sudo install -m 755 src/redis-cli /usr/local/bin/

    Amazon Linux

    If using Amazon Linux, enter this:

    sudo yum install gcc jemalloc-devel openssl-devel tcl tcl-devel clang wget wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make redis-cli CC=clang BUILD_TLS=yes sudo install -m 755 src/redis-cli /usr/local/bin/

    On Amazon Linux, you may also need to run the following additional steps:

    sudo yum install clang CC=clang make sudo make install
  3. After you have downloaded and installed the redis-cli utility, it is recommended that you run the optional make-test command.

  4. To connect to a cluster with encryption and authentication enabled, enter this command:

    redis-cli -h Primary or Configuration Endpoint --tls -a 'your-password' -p 6379
    Note

    If you install redis6 on Amazon Linux 2023, you can now use the command redis6-cli instead of redis-cli:

    redis6-cli -h Primary or Configuration Endpoint --tls -p 6379