Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect ElastiCache to Elastic Beanstalk Instance

I have been reading through the Elastic Beanstalk and ElastiCache documentation on creating a connection between my EB instance and my Redis endpoint. I have added my endpoint to my session configuration in my Node.js app, but it doesn't appear that it is connecting to my Redis instance as indicated by an error that is getting thrown when accessing any pages that use the session. I know that the security groups between the Elastic Beanstalk and ElastiCache need to be the same, but do I need make adjustments to my environment to attach the two?

Here is my Redis connection in my Node.js app:

//Session Cookie
app.use(cookieParser());
app.use(session({
    store: new RedisStore({
        host: 'redis-production.dfdfa.0001.use1.cache.amazonaws.com',
        port: 6379
    }), 
    secret: process.env.SECRET,
    resave: true,
    saveUninitialized: true,
    cookie: {
        httpOnly: true,
        secure: false //turn to true on production once https is in place
    }
}));
like image 861
cphill Avatar asked Aug 15 '16 00:08

cphill


People also ask

How do I connect Elastic Beanstalk instance?

Right-click the instance ID for the Amazon EC2 instance running in your environment's load balancer, and then select Connect from the context menu. Make a note of the instance's public DNS address on the Description tab. Connect to an instance running Linux by using the SSH client of your choice, and then type ssh -i .

How do I connect ElastiCache to EC2?

Choose the box to the left of default security group. From the list at the bottom of the screen, choose the EC2 Security Group Name you want to authorize. To authorize access, choose Add. Amazon EC2 instances that are associated with the security group are now authorized to connect to your ElastiCache cluster.

How do I connect Redis ElastiCache?

Sign in to the AWS Management Console and open the ElastiCache console at https://console.aws.amazon.com/elasticache/ . From the navigation pane, choose Redis clusters. The clusters screen will appear with a list of Redis (cluster mode disabled) and Redis (cluster mode enabled) clusters.


1 Answers

I'm not sure what you mean by this:

I know that the security groups between the Elastic Beanstalk and ElastiCache need to be the same

They don't need to be the same security group, if that is what you are saying. And they don't need to have the exact same settings, if that is what you are saying. Here's what you need to do:

  1. Elastic Beanstalk Servers are in a specific security group. We will call this SG1.
  2. ElastiCache instances are in a specific security group. We will call this SG2.
  3. Add a rule in SG2 that allows traffic on the port you specified when you configured the ElastiCache instances. The default port is 6379. In this Security Group rule use the ID of SG1 in the source field. For example if SG1 has an ID of sg-123456then enter that in the source field.

Once you have completed those steps then all Elastic Beanstalk instances will have access to your ElastiCache Redis instance(s).

like image 122
Mark B Avatar answered Oct 06 '22 21:10

Mark B