How to connect to AWS elasticache? - amazon-web-services

Could someone give a step-by-step procedure for connecting to elasticache.
I'm trying to connect to a redis elasticache node from inside my EC2 instance (sshed in). I'm getting Connection Timed Out errors each time, and I can't figure out what's wrong with how I've configured my AWS settings.
They are in different VPCs, but in my elasticache VPC, I have a custom TCP inbound rule at port 6379 to accept from anywhere. And the two VPCs share an Active Peer connection that I set up. What more am I intended to do?
EDIT:
I am trying to connect via the redis-cli command. I sshed in because I was originally trying to connect via the node-redis module since my EC2 instance hosts a node server. So officially my two attempts are 1. A scripted module and 2. The redis-cli command provided in the AWS documentation.
As far as I can tell, I have also set up the route tables correctly according to this: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Route_Tables.html#route-tables-vpc-peering

You cannot connect to Elasticache from outside its VPC. It's a weird design decision on AWS' part, and although it's not documented well, it is documented here:
Amazon ElastiCache Nodes, deployed within a VPC, can never be accessed from the Internet or from EC2 Instances outside the VPC.
You can set your security groups to allow connections from everywhere, and it will look like it worked, but it won't matter or let you actually connect from outside the VPC (also a weird design decision).

In your Redis cluster properties you have a reference to the Security Group. Copy it.
In our EC2 instance you also have a Security Group. You should edit this Security Group and add the ID of the Redis Security Group as CIDR in the outbound connections + the port 6379.
This way the two Security Groups are linked and the connection can be established.

Two things we might forget when trying to connect to ElasticCache,
Configuring inbound TCP rule to allow incoming requests on port 6379
Adding EC2 security group in ElasticCache instance
Second one helped me.
Reference to (2) : https://www.youtube.com/watch?v=fxjsxtcgDoc&ab_channel=HendyIrawanSocialEnterprise

Here is step-by-step instructions for connection to Redis Elasticache cluster from EC2 inctance located in the same VPC as Elasticache:
Connect to a Elasticache Redis Cluster's Node

Related

Instance not able to communicate - Same VPC & Subnet, Different Security Group

I have created a CloudFormation template and deployed it successfully. I have two EC2 Instances in SAME VPC, SAME SUBNET but different security group. One of the EC2 instance is MongoDB server installed on it, other one have the node server running. I am able to access both instances without any issue, problem happens when I try to connect to MongoDB from Node Server. It doesn't work. I have drilled down the issue that both the servers are not able to connect to each other. Below are my security group for
DB Server
Application Server
I have already visited below threads in this regards but it did not help.
EC2 instance can't connect to RDS, from same VPC/Subnet
CloudFormation - Security Group VPC issue
You aren't allowing outgoing traffic from your application server over port 12077. I would really recommend deleting all the SecurityGroupEgress rules and allowing the default of all egress allowed.

Securing AWS ECS Cluster

We are trying to create an ECS Cluster however we noticed that the internal ECS Agent is unable to register. We unblocked TCP 443 (ACL and SG) however it still did not register. We then proceeded to open up everything All Traffic both TCP and UDP and then the agent was able to register.
We tried to investigate what is being used using FlowLogs but it seems that the agent is using a random port and a different IP each time which makes it almost impossible for us to secure our network due to the agent. We tried and searched a lot for documentation about how and what the ECS Agent needs to run properly to no avail.
What we would like to achieve is to secure our network while allowing the agent to function as needed. Perhaps a better question would be which ports is the ecs-agent trying to use exactly and to which IPs should we allow that traffic to come from/go to?
From just 1 hour the flow log shows IPs from all over the world trying to hit the servers it just doesn't make sense not to prioritize this matter.
The ECS agent needs outgoing internet access to register itself to the cluster.
Here are some steps to try:
Check the security group on the EC2 instances to ensure they're
allowing outbound traffic.
Check your VPC config where the ECS instances are running and ensure they have internet access.
VPC Route Tables to ensure it's routing
destination 0.0.0.0/0 to your Internet Gateway.
Check your ACLs rules and ensure your outbound rules
match your inbound - which has bitten me a few times!

Cant connect redis-cli with amazon elastic cache

I have created a redis endpoint on amazon elastic cache and also setup vpc & NAT gateway. I need to connect created redis endpoint with redis-cli. i using command like this
redis-cli -h dev-redis.434dffsdsf.0094.ustyue1.cache.amazonaws.com
But i got error message like this
Could not connect to Redis at dev-redis.a35gy4.0001.use1.cache.amazonaws.com:6379: Connection timed out
I tried with several ways
tried to connect from my local ubuntu machine.
tried to connect from a ec2 instance.
My source code is running on aws lambda. Using aws lambda we can successfully connect to the same redis endpoint.
What is the actual issue with my redis client?
Please check SG of ElastiCache. Redis instance should be accessible to server where you're running Redis CLI.
Option 1 will not work, as ElastiCache instances are not accessible outside of their VPC. From the FAQs: "Amazon ElastiCache Nodes, deployed within a VPC, can never be accessed from the Internet or from EC2 Instances outside the VPC."
Option 2 should work, if the EC2 instance is within the same VPC as the ElastiCache instance.
Adding more details as none of the answers here gave me full clarity
What is security group - security group in AWS is like a firewall.
What should I check in the security group - Check in inbound rules of the security group attached to the Redis if port 6379 is open to IPs within the CIDR (e.g. 192.168.32.0/20) of the EC2 instance from which you tried to access the Redis/ElasticCache

How to connect to a RDS instance in a different AWS region

I have an EC2 instance in one region, N.California. I have an RDS instance in EU/Ireland. I am not able to connect to the RDS instance from the EC2 instance, the connection times out. This tutorial by aws says that I would need to use the Public IP of the RDS instance in order to connect to it. But this public IP is not available on the AWS console, I'm not even sure if we're supposed to be using any other than RDS endpoints. We're also disallowed from adding a security group from one region to the security group of another.
I am really unsure about how to proceed.
I am answering my own question because my own solution worked, and it might be of use to someone else considering that the AWS tutorial is wrong.
To connect, add a custom tcp rule over port 3306 in the security group Ingress Rules for the RDS instance, with the EIP of your EC2 instance as the allowed host. Voila.

AWS Elasticache Timeout from EC2

I am getting connection timeout from EC2 trying to connect to AWS Elasticache.
I launched a 1-node elasticache cluster
I launched an EC2 instance, made sure availability zone was the same as the cluster, us-west-2b
I did not create a new VPC. I see one is already created.
I ran a nslookup on my elasticache endpoint. It looks like a different /20 than my ec2.
I looked through the documentation and the ec2 launch and did not see where I can specify the subnet, except the availabilty zone.
I think the problem is about security groups of your instance.
To the best of my knowledge you need to allow the traffic on the security group associated to your EC2 instance.
If you are using memcached the port is 11211 if redis the port is 6379
Try to have a look to the AWS official documentation.
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.AuthorizeAccess.html
I hope this helps somehow.
Actually solution is to add security group to elasticache cluster, and this security group should allow 6379 port.
First, check the instance security group and check port 6379 is allowed in Inbound.
After that, check your default VPC security group and add inbound rule Custom TCP Rule-6379-Anywhere and save.
I hope this will fix the issue.