Step 3: Connect to the cluster - Amazon MemoryDB for Redis

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. 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 following commands:

    Amazon Linux 2

    $ 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

    $ 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/
  3. After this, it is recommended that you run the optional make-test command.

  4. At the command prompt of your EC2 instance, type the following command, substituting the endpoint of your cluster and port for what is shown in this example.

    src/redis-cli -c -h Cluster Endpoint --tls -p 6379