Django, Redis & AWS ElastiCache primary/replica cluster

AWS’s ElastiCache service is a convenient way to launch a Redis cluster. If you’re using Django, both django-redis-cache and django-redis packages support an ElastiCache Redis instance. If you are launching ElastiCache Redis with any amount of replicas, some additional master-slave configuration is needed in your Django settings.

Here is an example of an ElastiCache Redis cluster with a primary instance and two replicas:

The following is an example of the correct settings for this cluster if you’re using django-redis-cache backend:

    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': [
        'OPTIONS': {
            'DB': 0,
            'MASTER_CACHE': ""

Elastic Beanstalk npm install error EACCES: permission denied, mkdir ‘/home/webapp’

Ran into an error while deploying to an AWS Elastic Beanstalk instance set up for Rails + Node + Webpack.

Full error during npm install:

npm install
npm ERR! Linux 4.4.23-31.54.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/support/node-install/node-v4.6.0-linux-x64/bin/node" "/usr/bin/npm" "install"
npm ERR! node v4.6.0
npm ERR! npm  v2.15.9
npm ERR! path /home/webapp
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/home/webapp'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/home/webapp']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/webapp',
npm ERR!   parent: 'testing-app' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

After some Googling, this Stack Overflow thread gave me some clues: Deploying a Rails / Ember app on AWS Elastic Beanstalk

The /home/webapp directory needed to be created during deploy. This was accomplished using a .ebextensions config with a commands stanza. Docs on commands here

The final commands I used are as follows:

    command: mkdir /home/webapp
    ignoreErrors: true
    command: chown webapp:webapp /home/webapp
    ignoreErrors: true
    command: chmod 700 /home/webapp
    ignoreErrors: true