Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Logging with Elastic Beanstalk (AWS)

I am deploying a web service built on Django/Python at AWS using Elastic Beanstalk. I am using Django's logging feature to log website use and related data. While that worked fine with local testing, I an unable to get this to work with Beanstalk.

My code to log in settings.py is:

# Django Logging

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
        'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'spareguru.log',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'handlers':['file'],
            'propagate': True,
            'level':'DEBUG',
         },
        'customer': {
            'handlers': ['file'],
            'level': 'DEBUG',
         },
    }
}

The error I get while deploying to Beanstalk is:

ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/opt/python/bundle/3/app/spareguru.log'

I also tried creating a file using .ebextensions and making wsgi the owner of that file but that didn't work either.

How can I fix this?

like image 843
Gaurav Wadhwani Avatar asked Sep 17 '15 14:09

Gaurav Wadhwani


People also ask

Can Django be used with AWS?

Django comes with a development server that helps run Django projects in localhost. However, to make your web application available worldwide you will need a host machine. Amazon Web Services (AWS) provides EC2 (Elastic Compute Cloud) which is the most popular choice to host Django web applications.

How do I add logging to Django project?

First Steps With Logging Begin by updating the app/views.py file with the following code: import logging from django. http import HttpResponse # This retrieves a Python logging instance (or creates it) logger = logging. getLogger(__name__) def index(request): # Send the Test!!

What is the difference between AWS CodeDeploy and Elastic Beanstalk?

Elastic Beanstalk and CodeDeploy are both very similar deployment products with one major difference: resource management. AWS CodeDeploy is a service that automates code deployments to currently running EC2 instances.


1 Answers

You do not have sufficient rights on the server for create log file. Сonfigure SSH and using CHMOD to change permission for folder

Configure the environment of your Elastic Beanstalk Application (for SSH) - enter link description here

like image 107
Jonh Maker Avatar answered Oct 04 '22 21:10

Jonh Maker