Elastic Beanstalk Static Folder 403 Error - python

I'm stuck trying to solve a "403 Forbidden" error in my Elastic Beanstalk Flask application. I have set up my python.config file as below:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/static/": "/static/"
"/templates/": "/templates/"
commands:
01_set_file_permissions:
command: "chmod 777 /opt/python/current/app/static/"
The static folder was initially giving a 404 but the static files section of python.config fixed that. My problem is I can't get the file permissions to be recognised on the server. It always returns a 403 error. Please help.

I worked out the fix. The option_settings section was incorrect in that the route to folder was not given as a relative path. Also the /static/ folder was already set via a hard-coded value in the AWS console at:
AWS > Elastic Beanstalk > > Configuration > Software Configuration > Virtual Path. I needed to change the value of /static/ to static/ here.
Finally the commands section was not required at all. The fixed python.config file (that works) is as follows:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/templates/": "templates/"

Related

Uploading large files to AWS Elastic Beanstalk / nginx

I have an application that uploads a file which works fine on Heroku and on local developer machines - but on AWS EB, the upload is interrupted and doesn't complete.
I've set the nginx directives as follows
.ebextensions/00_project.config
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 2000M
client_body_buffer_size 2000M
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: server:application
.platform/nginx/conf.d/proxy.conf
client_max_body_size 2000M;
client_body_buffer_size 2000M;
.platform/nginx/00_myconf.config
container_commands:
01_reload_nginx:
command: "service nginx reload"
This is running python3.8 and using a plotly/react framework called Dash. https://dash.plotly.com/introduction
As mentioned, it's only not working on AWS so it appears to be a system config issue. To confirm this, I uploaded a large file to a public bucket and had this app read from the bucket instead of the upload and it worked fine.
I've exhausted all options so any help muchly appreciated!
After prompting from kgiannakakis, I checked the logs and was found a "web: MemoryError" line in the web.stdout.log file.
So I upgraded the EB instance to something a bit bigger and it managed to fix the issue... so essentially I was running out of memory and needed to pay AWS more money to get more memory.

AWS WSGIPath refers to a file that does not exist

I have been going through every thread on here and have tried all the ways I can think of. I am following the AWS deploy django tutorial and keep getting this error
ERROR Your WSGIPath refers to a file that does not exist.
I have used eb config to edit the file to the same path thats in django.config which is endjango/wsgi but nothing I have tried has worked. Also tried wrapping it in quotes and that did not work either.
Heres my file
django.config
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: ebdjango/wsgi.py
Config.yml
branch-defaults:
default:
environment: django-env
group_suffix: null
global:
application_name: django-tutorial
branch: null
default_ec2_keyname: aws-eb
default_platform: python-3.6
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
Figured out the issue ebextensions and requirements.txt need to be in root folder. Next run eb config and edit wsgi path to match endjango/wsgi.py.
You can also configure your wsgi path from UI. Go to configure tab and edit it there. Another option is using terminal.

Django Deployment Server serving Static Files with only uWSGI

im trying to get my Django App to run using only uWSGI. The project is not that big, so i would really prefer to leave nginx out.
I just can't get uWSGI to show my static files though. I've gone through the settings multiple times and can't find the problem.
I have the STATIC_URL set to 'module/static/'
STATIC_ROOT set to '/module/static_files/' (i read somewhere that they should not be the same)
and my uwsgi.ini looks like this:
[uwsgi]
module=Module.wsgi:application
master=True
http=:80
processes=4
threads=2
static-map /static= /module/static_files/
the projects file structure is set up in the following way:
-- Project:
---init.py
---settings.py
---urls.py
---wsgi.py
-- Logs
-- module
---static
---static_files
---[... module template, model, urls etc]
-manage.py
-db.sqlite3
I can run collectstatic and generate all the static files in the correct folder.
But when i run the uwsgi script, it wont work and gives me a 404 file not found for all static files.
I would really appreciate any help, I've been stuck on this for an entire week now...
(i have checked out Deployment with Django and Uwsgi
but as far as i can tell, my static-map is set correctly)
you need to add your static files as static-map=/static=/module/static_files/

Django; AWS Elastic Beanstalk ERROR: Your WSGIPath refers to a file that does not exist

I am using this tutorial:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
I create the .ebextensions directory inside the root directory, and put this django.config file in it:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: mysite/wsgi.py
I've also tried setting the path to mysite/mysite/wsgi.py because I saw that work somewhere but it did not help me.
Everywhere I look shows a different .config file with different arrangements, and I don't know where to go from here. How can I properly set my WSGIPath in Elastic Beanstalk?
[Solution]
1 eb config
2 Change the WSGIPath there from application.py to mysite/wsgi.py
That's It
I ran into a similar issue, and it seemed to resolve when I put .elasticbeanstalk in the same directory as .ebextensions, rather than having it be a child directory. Then I had to run eb config to fix the wsgi file that it was de facto picking up, and now I have a running app.
Make sure that .ebextensions isn't ignored. EB looks for .ignore file (.ebignore by default and if it doesnt exists but .gitignore does, it will use it) and deploy only the files that are not ignored. Had a similar issue with my local_settings.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore
I did not use console but GUI.
ERROR: Your WSGIPath refers to a file that does not exist.
where could be problem : Creating .zip file
select all : files of your project (not the project folder)
Note : weworkout is my django project (created by django-admin startproject
weworkout)
Right way : select all files
Wrong way : selecting project folder
Also this is the only change you have to do to your django project before uploading
weworkout/.ebextensions/django.config file contains
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: weworkout/wsgi.py
Note : .ebextensions is in same folder as manage.py
If you see the following error:
ERROR: Your WSGIPath refers to a file that does not exist.
Note the following:
EC2 (server) instances in EB (platform) run Apache.
Apache finds Python apps according to our WSGIPATH.
By default EB assumes the WSGI file is called application.py.
There are two ways of correcting this.
Option 1: Using environment-specific configuration settings
Run: $ eb config
Find the following config file “.elasticbeanstalk/src-test.env.yml.”
This file doesn’t actually exist locally; EB pulled it so that you can edit it.
If you save changes in this pseudo-file, EB will update the corresponding settings in your env.
If you search for the terms ‘WSGI’ in the file, you should find a config section resembling this:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: application.py
Update the WSGIPath:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: src/src/wsgi.py #src/src is an example. Do not just c&p.
If you save the file, EB will update the env config automatically.
The advantage to using the $ eb config method to change settings is that you can specify different settings per env.
Option 2: Using global configuration settings
To use this option, create a new file called /.ebextensions/02_python.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: “src.settings" #src is an example.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" #src is an example.
"aws:elasticbeanstalk:container:python":
WSGIPath: src/src/wsgi.py #src is an example.
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
What’s happening?
DJANGO_SETTINGS_MODULE: "src.settings" - adds the path to the settings module.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" - updates our PYTHONPATH so Python can find the modules in our application.(Note that the use of the full path is necessary.)
WSGIPath: src/src/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 - updates the number of processes and threads used to run our WSGI application.
"/static/": "www/static/" sets our static files path.
Run $ git commit (if necessary) and $ eb deploy to update these settings.
Check if your Django.config file was saved with the correct extension. I had the same issue and the problem was that the file was being saved as a TXT file instead of config file.

Amazon Elastic Beanstalk : how to set the wsgi path?

I practice set up Django under Elastic Beanstalk from there document.
But There is error.
ERROR Your WSGIPath refers to a file that does not exist.
My directory like this:
-djangoenv (where I use git)
- mysite
-manage.py
-mysite
-__init__.py
-settings.py
-urls.py
-wsgi.py
and My the .elasticbeanstalk/optionsettings.djapp file like this :
And .ebextensions/python.config like this , I don't know where to put this .try several times still not work . I try mysite/mysite/wsgi.py still not work
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
Please tell me how and where to set my wsgi path ??
Thank you very much!
I found that you have to restart the server for it to take these changes into consideration.
I spent ages changing and tweaking these options and nothing worked. Then when I went to the EB console and restarted the environment it worked.
In the server you are about to deploy the django application to elasticbean stalk. Run:
eb config
Then replace the application.py to mysite/wsgi.py and save the changes.
After the update, you may do:
git add.
git commit -m "some updates"
eb deploy
After successfully update the environment, you may view the changes in elasticbeanstalk, under your enviroment, go to the instance and check the setting in Configuration, then view the WSGIPath under Software Configuration.
Disclaimer: This information is valid until 4 November 2016. AWS may further change the setting.
The path specified should be relative to the .elasticbeanstalk directory.
The correct path should be mysite/mysite.wsgi.py. option_settings: is:
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
You have WSGIPath set to "application.py" but your WSGI file is "mysite/wsgi.py".
You should try
mysite.wsgi:application and make sure you are in the mysite first folder while deploying your application

Categories

Resources