Menu
Amazon ElastiCache
User Guide (API Version 2015-02-02)

Connecting to a Cluster or Replication Group Running in an Amazon VPC

This example shows how to launch an Amazon EC2 instance in your Amazon VPC. You can then log in to this instance and access the ElastiCache cluster that is running in the Amazon VPC.

Note

For information about using Amazon EC2, see the Amazon EC2 Getting Started Guide in the Amazon EC2 documentation.

1. Create an Amazon EC2 Instance

The following procedure creates an Amazon EC2 instance in your VPC.

  1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the console, choose Launch Instance and follow these steps:

  3. On the Choose an Amazon Machine Image (AMI) page, choose the 64-bit Amazon Linux AMI, and then choose Select.

  4. On the Choose an Instance Type page, choose 3. Configure Instance.

  5. On the Configure Instance Details page, make the following selections:

    1. In the Network list, choose your Amazon VPC.

    2. In the Subnet list, choose your public subnet.

    When the settings are as you want them, choose 4. Add Storage.

  6. On the Add Storage page, choose 5. Tag Instance.

  7. On the Tag Instance page, type a name for your Amazon EC2 instance, and then choose 6. Configure Security Group.

  8. On the Configure Security Group page, choose Select an existing security group.

    Choose the name of your Amazon VPC security group, and then choose Review and Launch.

  9. On the Review Instance and Launch page, choose Launch.

    In the Select an existing key pair or create a new key pair window, specify a key pair that you want to use with this instance.

    Note

    For information about managing key pairs, go to the Amazon EC2 Getting Started Guide.

  10. When you are ready to launch your Amazon EC2 instance, choose Launch Instances.

2. Assign IP Address to Your Amazon EC2 Instance

You can now assign an Elastic IP address to the Amazon EC2 instance that you just created. You need to use this IP address to connect to the Amazon EC2 instance.

  1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/.

  2. In the navigation list, choose Elastic IPs.

  3. Choose Allocate New Address.

  4. In the Allocate New Address dialog box, in the EIP used in box, choose VPC, and then choose Yes, Allocate.

  5. Choose the Elastic IP address that you just allocated from the list and choose Associate Address.

  6. In the Associate Address dialog box, in the Instance box, choose the ID of the Amazon EC2 instance that you launched, and then choose Yes, Associate.

    You can now use SSH to connect to the Amazon EC2 instance using the Elastic IP address that you created.

    Tip

    For instructions about using SSH to connect to a Linux/UNIX instance, see Connect to Your Linux/UNIX Instance in the Amazon EC2 Getting Started Guide.

3. Connect to Your Amazon EC2 Instance

The following steps connects you to your Amazon EC2 instance.

  1. Open a command window. At the command prompt, issue the following command, replacing mykeypair.pem with the name of your key pair file and 54.207.55.251 with your Elastic IP address.

    Copy
    ssh -i mykeypair.pem ec2-user@54.207.55.251

    Important

    Do not log out of your Amazon EC2 instance yet.

  2. You are now ready to interact with your ElastiCache cluster. Before you can do that, if you haven't already done so, you need to install the telnet utility.

    To install telnet and interact with your cache cluster (AWS CLI)

    For Linux, OS X, or Unix:

    Open a command window. At the command prompt, issue the following command. At the confirmation prompt, type y.

    Copy
    sudo yum install telnet Loaded plugins: priorities, security, update-motd, upgrade-helper Setting up Install Process Resolving Dependencies --> Running transaction check ...(output omitted)... Total download size: 63 k Installed size: 109 k Is this ok [y/N]: y Downloading Packages: telnet-0.17-47.7.amzn1.x86_64.rpm | 63 kB 00:00 ...(output omitted)... Complete!

    For Windows

    Open a command window. At the command prompt, issue the following command. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.

    Copy
    pkgmgr /iu:"TelnetClient"
  3. Go to the ElastiCache console at https://console.aws.amazon.com/elasticache/ and obtain the endpoint for one of the nodes in your cache cluster.

  4. Use telnet to connect to your cache node endpoint over port 11211. Replace the hostname shown below with the hostname of your cache node.

    Copy
    telnet my-cache-cluster.7wufxa.0001.use1.cache.amazonaws.com 11211

    You are now connected to the cache engine and can issue commands. In this example, you add a data item to the cache and then get it immediately afterward. Finally, you'll disconnect from the cache node.

    To store a key and a value, type the following two lines:

    Copy
    add mykey 0 3600 28 This is the value for my key

    The cache engine responds with the following:

    STORED

    To retrieve the value for mykey, type the following:

    Copy
    get mykey

    The cache engine responds with the following:

    Copy
    VALUE mykey 0 28 This is the value for my key END

    To disconnect from the cache engine, type the following:

    Copy
    quit

Important

To avoid incurring additional charges on your AWS account, be sure to delete any AWS resources you no longer want after trying these examples.