AWS ElastiCache - Memcached VPC


The VPC of the EC2 instance used for connecting to the Memcached cluster may not be the same VPC in as that of the cluster. In such cases we need to allow the connection between these two VPCs so that they can interact. From the previous chapter, we have already seen an EC2 instance running in the default VPC. Now we create an additional VPC to which we can associate the Memcached cluster and then establish a connection to the EC2 instance through peering mechanism.

This will need the following steps to be followed.

Creating a New VPC

To create a new VPC, we go to the VPC dashboard from the homepage of AWS account. Then we click on the Create VPC button which will prompt us for the name of the VPC and CIDR block address etc. After filling in those details we can see the following VPC being created. Please note that we have to careful in mentioning the CIDR block as that should not overlap with the CIDR block of existing VPC which has the EC2 instance.

Creating in different vpc 1

Creating a VPC Peering

Next, we create a peering connection between the above to VPCs. From the VPC dashboard, we choose the Peering Connections option in the left tab. That brings up the following screen which we need to fill in as shown below.

Creating in different vpc 2

After clicking on the create Peering Connection button above, we have to accept the peering connection request as shown in the screen shot below.

Creating in different vpc 3

Next, we edit the route table to reflect the target gateway in the other VPC. This will enable the connection between the VPCs.

Creating in different vpc 4

Finally, we can see the peering connection to be active which will enable us to connect to the ElastiCache VPC from the another VPC where the EC2 is located.

Creating in different vpc 5