22

AWS has Redis support via the ElastiCache Service. My question is, can I connect to Redis on AWS Elasticache from node, using the following:

var client = require('redis').createClient(6379, 'elastichache endpoint string', {no_ready_check: true});

Or do I have to use the NodeJS AWS SDK?

I realize I could set up my own Redis Server on an EC2 instance, but I want to use ElastiCache. Is this possible?

user602525
  • 2,968
  • 4
  • 20
  • 37

1 Answers1

33

Yes, this is a common use case. You can connect directly to redis without using the SDK. Just make sure you have configured the security group correctly to allow access from your app server.

Ben Whaley
  • 26,347
  • 4
  • 75
  • 77
  • 10
    Just to add on to this answer, elasticache is only available within your vpc on AWS, so you cannot connect to it from a client outside of your VPC. – user602525 Jan 14 '15 at 20:41
  • @user602525 can you explain your comment in detail ? – Rishabh Agrawal May 17 '17 at 21:22
  • 1
    @ANinJa, it can't be accessed from outside AWS, meaning you can't directly connect to it. If you are accessing it from machines running on AWS then you should be fine, but if you are testing locally for example on your PC you will never be able to connect to the redis instance. You've gotta do it from inside AWS – user602525 May 18 '17 at 16:41
  • @user602525 you mean i cant use it when my server is not on aws even i open inbound to redis server and connect it through my main server(hosted on digitalocean) ? – Rishabh Agrawal May 19 '17 at 10:55
  • @ANinJa Correct – user602525 May 19 '17 at 14:01
  • Looks like noderedis doesn't work with AWE elasticache dns – Madeo Mar 30 '20 at 23:44
  • @user602525 I am trying to connect to Elasticache Redis cluster from local and getting timeout errors even after allowing security groups to access from any IP. While I am able to connect to it using EC2 instance. What should be the option to connect it locally? or from Lambda function? – Avani Khabiya Dec 16 '20 at 06:54
  • @AvaniKhabiya you need to access it from within the same VPC elasticcache is in. So you would either need to proxy your requests through an EC2 machine or set up a VPN so you can VPN into your VPC or something similar. – user602525 Dec 17 '20 at 07:30
  • @user602525 Can you please elaborate. How will I access Elasticache in same VPC from nodejs? I have tried accessing it from EC2 instance using ssh, but have no clue to access from node, can you help? – Avani Khabiya Dec 21 '20 at 09:16