DEV Community


Posted on

Easy way to connect to Amazon ElastiCache (redis) with password from Django app


  • ElastiCache (redis) instance

  • your Django app

  • git

  • pip package manager

install redis

install redis by below command

pip install redis
Enter fullscreen mode Exit fullscreen mode

Copy the part of django-redis-sessions in your project directory

  • Clone to any directory

Clone git repository wherever you want to put.

git clone
Enter fullscreen mode Exit fullscreen mode
  • Copy redis_sessions to your project directory

Copy redis_sessions directory in django-redis-sessions to your project directory.

cp -r redis_sessions your_directory
Enter fullscreen mode Exit fullscreen mode
  • Edit and your

Open below files with editor, and add the codes.


    def get(self):
        elif self.connection_type == 'redis_host':
            # add below code


# add below code
SESSION_ENGINE = 'your_directory.redis_sessions.session'

    'host': 'your_aws_elasticache_endpoint_name',
    'port': your_port,
    'db': 0,
    'password': your_password,
    'prefix': 'session',
    'socket_timeout': 3,
    'retry_on_timeout': False
Enter fullscreen mode Exit fullscreen mode

※ In your password setting, using encryption middleware such as django-environ, python-decouple is better.

The reason why we edit is to use SSL mode. By doing that, we can connect to ElastiCache by SSL tunnel mode.

Finish! Check Connection

Confirm by running the server, testing, or connecting to ElastiCache directly, etc.

I hope I can help you to deploy your Django app to AWS!!

Top comments (1)

priyanshupanwar profile image
Priyanshu Panwar

Thanks a lot for this.
Can you please provide the git link of this project.
Would be really helpful.