dev53
dev53

Reputation: 414

AWS Elastic Beanstalk EC2 With Redis - Cannot Connect - Django_Redis

Hi I am trying to connect my Django application to use Redis ElastiCache and am having trouble with getting it connected using AWS. The application is published to an EC2 instance using Elastic Beanstalk and it running perfect when I am not trying to connect to my Redis cache.

From the post here (Setting up ElastiCache Redis with Elastic BeanStalk + Django) I created my ElastiCache to not use a cluster and I have set up both the EC2 instance and the Redis cache to use the same Security Group.

Here is how my cache is configured in settings.py.

CACHES = {
'default': {
    'BACKEND': 'django_redis.cache.RedisCache',
    'LOCATION': 'redis://my-cache.kjshd.0001.use2.cache.amazonaws.com:6379/',
    'OPTIONS': {
        'CLIENT_CLASS': 'django_redis.client.DefaultClient'
    }
  }
}

What am I missing? Are there additional settings that need changed on my cache or somewhere in AWS to open communication? Does this configuration look okay? I was previously using Redis in Azure and this configuration worked but now have the requirement to move to AWS. Is there a way to test that my EC2 instance can connect to Redis? I have the ability to SSH into the server but I was not sure what I would do once I was connected.

Thanks for any help.

Upvotes: 1

Views: 2876

Answers (2)

Murtaza Arif
Murtaza Arif

Reputation: 53

Add redis.config in .ebextensions

packages: 
  yum:
    gcc-c++: [] 
    make: []
sources:
  /home/ec2-user: http://download.redis.io/releases/redis-5.0.5.tar.gz
commands:
  redis_build:
    command: make
    cwd: /home/ec2-user/redis-5.0.5
  redis_config_001:
    command: sed -i -e "s/daemonize no/daemonize yes/" redis.conf
    cwd: /home/ec2-user/redis-5.0.5
  redis_config_002:
    command: sed -i -e "s/# maxmemory <bytes>/maxmemory 500MB/" redis.conf
    cwd: /home/ec2-user/redis-5.0.5
  redis_config_003:
    command: sed -i -e "s/# maxmemory-policy volatile-lru/maxmemory-policy allkeys-lru/" redis.conf
    cwd: /home/ec2-user/redis-5.0.5
  redis_server:
    command: src/redis-server redis.conf
    cwd: /home/ec2-user/redis-5.0.5

add connect to localhost

Upvotes: 0

dev53
dev53

Reputation: 414

After setting the security group, I found out that I needed to change the inbound settings for the security group to connect to my ElastiCache Redis node.

Documentation was found here.

https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.AuthorizeAccess.html#GettingStarted.AuthorizeAccess.VPC

Upvotes: 2

Related Questions