Peter
Peter

Reputation: 152

wsgi user permissions on elastic beanstalk

I'm using elastic beanstalk and django. One of my dependencies in my requirements.txt file has some setup the it performs when it's initially imported. Part of the setup is to check whether a dir exists else it create it. I'm getting permissions errors because the user ( I assume it's wsgi) does not have the permissions to create the dir.

OSError: [Errno 13] Permission denied: '/home/wsgi/.newspaper_scraper/memoized'

How can I setup permissions to allow for these dirs to be created in a way that will be persistent across instances I create in the future?

Upvotes: 3

Views: 1149

Answers (1)

Daniel van Flymen
Daniel van Flymen

Reputation: 11551

This is happening because the uWSGI worker is running under a user with limited permissions. You need to create the .newspaper_scraper/memoized directory first, and set the correct permissions on it (allow others to r/w). You can do this on deployment by making a script in .ebextensions that EB executes upon deployment.

Create a file in .ebextensions/setup_newspaper.config and add the following to it:

.ebextensions/setup_newspaper.config

packages:
  yum:
    libxslt-devel: []
    libxml2-devel: []
    libjpeg-devel: []
    zlib1g-devel: []
    libpng12-devel: []

container_commands:
  01_setup_newspaper:
    command: mkdir -p /home/wsgi/.newspaper_scraper/memoized && chmod 644 /home/wsgi/.newspaper_scraper/memoized


PS: It looks like newspaper requires some extra packages to be installed, so I added them too.


Read more info on .ebextensions here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-container.html#create-deploy-python-custom-container

Upvotes: 3

Related Questions