Wai Yan Hein
Wai Yan Hein

Reputation: 14791

Laravel: connecting the AWS ElasticCache Redis is timing out

I am working on a Laravel application. I using Redis and I am using AWS ElasticCache service for that. I am trying to connect to the Redis from my Laravel application. But it is timing out. This is what I have done.

I installed the Predis library by running the following command.

composer require predis/predis

Then I created a Redis instance in the ElastiCache service console enabling AUTH setting my password token.

Then I set the variables in the .env files.

CACHE_DRIVER=redis
REDIS_CLIENT=predis
REDIS_HOST=master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com
REDIS_PASSWORD=mypassword
REDIS_PORT=6379

When I run the code to connect to the Redis, I got the following error.

Operation timed out [tcp://master.laravelredistest.8sm3xo.euw1.cache.amazonaws.com:6379]

What is missing with my configuration and how can I fix it?

I also updated the security group of Redis to allow the EC2 instance's security group in the inbound rules as follows:

enter image description here

I am getting this error this time:

enter image description here

I edited the SG of Redis to add the following inbound rule too.

enter image description here

The security groups are in the same VPC too as you can see in the screenshot:

enter image description here

Upvotes: 3

Views: 2296

Answers (1)

Chris Williams
Chris Williams

Reputation: 35188

This sounds like a security group issue causing the timeout.

Elasticache clusters are always private so if you're using a public ip address, this will need to be updated to be the private ip address range of your instance/subnet/VPC.

An Elasticache cluster is a resource in your VPC, therefore network transit needs to be allowed for the cluster to be accessible.

More information is available in the Accessing Your Cluster page.

Additional Configuration

This is the issue. I also needed to delete the existing Redis instance and create another one without AUTH token enabled.

Upvotes: 3

Related Questions