Requirements
ElastiCache (redis) instance
your Django app
git
pip package manager
install redis
install redis by below command
pip install redis
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 https://github.com/martinrusev/django-redis-sessions#django-redis-sessions
- 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
- Edit session.py and your settings.py
Open below files with editor, and add the codes.
# session.py
def get(self):
...
elif self.connection_type == 'redis_host':
...
db=settings.SESSION_REDIS_DB,
# add below code
SSL=True,
# settings.py
# add below code
SESSION_ENGINE = 'your_directory.redis_sessions.session'
SESSION_REDIS = {
'host': 'your_aws_elasticache_endpoint_name',
'port': your_port,
'db': 0,
'password': your_password,
'prefix': 'session',
'socket_timeout': 3,
'retry_on_timeout': False
}
β» In your password setting, using encryption middleware such as django-environ, python-decouple is better.
The reason why we edit session.py 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)
Thanks a lot for this.
Can you please provide the git link of this project.
Would be really helpful.