ECS cloudwatch task error: “The specified log group does not exist”

This quick one is just for the googlers.

Saw an error bringing up tasks on a fresh ECS cluster and task run. The task definition included configuration to send logs to a cloudwatch log group.

"logConfiguration": {
    "logDriver": "awslogs",
    "options": {
        "awslogs-group": "web",
        "awslogs-region": "us-west-2",
        "awslogs-stream-prefix": "ecs"
    }
}

Unfortunately this is missing a not well documented flag:

"awslogs-create-group": "true",

Adding this argument, along with the correct permissions to create log groups, allows the task to create the group and send logs. The following permission is needed on the task execution role:

logs:CreateLogGroup

Full docs here:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html

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:

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': [
            "test-001.730tfw.0001.use1.cache.amazonaws.com:6379",
            "test-002.730tfw.0001.use1.cache.amazonaws.com:6379",
            "test-003.730tfw.0001.use1.cache.amazonaws.com:6379"
        ],
        'OPTIONS': {
            'DB': 0,
            'MASTER_CACHE': "test-001.730tfw.0001.use1.cache.amazonaws.com:6379"
        },
    }
}

https://django-redis-cache.readthedocs.io/en/latest/advanced_configuration.html#master-slave-setup

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:

commands:
  01_mkdir_webapp_dir:
    command: mkdir /home/webapp
    ignoreErrors: true
  02_chown_webapp_dir:
    command: chown webapp:webapp /home/webapp
    ignoreErrors: true
  03_chmod_webapp_dir:
    command: chmod 700 /home/webapp
    ignoreErrors: true