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?
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.
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!!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With