In this tutorial we’ll learn how to create an Elasticache Memcached Cluster using a custom VPC.
A custom VPC is needed to follow this tutorial. You can create a VPC (10.0.0.0/16) with one subnet (10.0.1.0/24).
Creating the cache subnet
You’ll need to create a cache subnet in your VPC. Go to the ElastiCache console and click on the Cache Subnet Groups.
Click on the Create Cache Subnet Group. Add a name and description for this subnet group and select the VPC ID of your custom VPC.
Click on the Add button below to the Subnet ID dropdown box.
Launching a cluster
Click on the Cache Cluster link from the side menu. You’ll need to select the engine you wish to use (Redis or Memcached). We’ll be using Memcached.
Add a Cluster Name, select the free tier Node Type (cache.t2.micro) and set the Number of Nodes to 1.
Select the previously created Cache Subnet Group and choose the VPC Security Group you’d like to use. We’ll need to add a custom TCP/IP rule to the security group.
The cluster will be created in a couple of minutes.
You can see the detailed node information by clicking on “1 node”.
By clicking on the node you’ll be able to see metrics on how this particular node is running.
To be able to connect from your EC2 instance to the ElastiCache cluster you’ll need to add a new inbound rule to the Security Group.
Create a new custom TCP rule. Set the port number to 11211 (Memcached default port number) and set the source to 0.0.0.0/0 (any destination).
Testing connectivity between your EC2 instance and the ElastiCache cluster is easy. SSH into your EC2 instance (an instance in your custom VPC).
yum install telnet
Run the following command:
telnet eticket-cache.4xznmr.0001.euw1.cache.amazonaws.com 11211
Replace the endpoint with your node’s endpoint.
If everything works fine and the EC2 can establish a telnet connection to port 11211 of your ElastiCache node you should see something similar to this:
[root@ip-10-0-1-39 ec2-user]# telnet eticket-cache.4xznmr.0001.euw1.cache.amazonaws.com 11211 Trying 10.0.1.20... Connected to eticket-cache.4xznmr.0001.euw1.cache.amazonaws.com. Escape character is '^]'.
Creating an ElastiCache cluster is easy and fast using AWS. In my next tutorial I’ll show you how to connect to this cluster using GO. I’ll show you how ElastiCache can speed up your web app with some easy to follow labs.