Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opsworks : Rails Layer connect to Elasticache : Redis

I am attempting to connect my Rails Application running in Opsworks to an Elasticache Redis Layer. I just can't get it to work.

My current configuration:

1 Stack (2 instances)
Layers
- Rails App Server - MySQL

The rails app is in the AWS-OpsWorks-Rails-App-Server Security Group.

1 ElasticCache Cluster The ES cluster is in the default security sg-ff58559a (VPC)(active) Security Group.

I am using the 'Primary Endpoint' to attempt to connect.

This value is visible from the
ElastiCache>Replication Groups
dashboard.

It looks similar to this:
<name>.oveuui.ng.0001.use1.cache.amazonaws.com:6379

In my rails console (after SSH into the rails layer) I try:

>r = Redis.new(:url => 'redis://<name>.oveuui.ng.0001.use1.cache.amazonaws.com:6379')
>r.connected

The results is:

Redis::CannotConnectError: Timed out connecting to Redis on...
like image 985
mconlin Avatar asked Jan 30 '26 21:01

mconlin


1 Answers

If you launched your cluster into an Amazon Virtual Private Cloud (Amazon VPC), you can connect to your ElastiCache cluster only from an Amazon EC2 instance that is running in the same Amazon VPC. In this case, you will need to grant network ingress to the cluster. To grant network ingress from an Amazon VPC security group to a cluster:

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

2.In the left navigation pane, under Network & Security, click Security Groups.

3.In the list of security groups, click the security group for your Amazon VPC. If you are a new ElastiCache user, this security group will be named default.

4.Click Inbound tab, and then do the following:

a. Click Edit.

b. Click Add rule.

c. In the Type column, select Custom TCP rule.

d. In the Port range box, type the port number for your cache cluster node. This number must be the same one that you specified when you launched the cluster. The default ports are as follows:

 Memcached: port 11211

 Redis: port 6379

e. In the Source box, select Anywhere which has the port range (0.0.0.0/0) so that any Amazon EC2 instance that you launch within your Amazon VPC can connect to your ElastiCache nodes..

f. Click Save.

http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.AuthorizeAccess.html

like image 69
Dmitriy Kravchenko Avatar answered Feb 01 '26 12:02

Dmitriy Kravchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!