Skip to content
Advertisement

Serving static files in elastick beanstalk

I’m deploying a python3 flask application in aws elasitc beanstalk (Amazon Linux 2 platform). The folder structure is as follows:

|-app/
|-templates/
|-static/
|   |-css/
|   |-js/
|-app.py

In the template files, importing of static resources are defiled as: i.e. JS file:

<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.js') }}"></script>

In the EB configurations, I’ve defined the static resources as below

enter image description here

But the problem is, these resources are not loading and giving 404. i.e.: https://example.com/static/js/jquery.js cannot be loaded. But if I try https://example.com/js/jquery.js, it works.

Have I done the configurations wrong??

Advertisement

Answer

Based on the comments.

The issue was due to overwriting /static path. In python EB environments, /static path is used by default to server the static content:

By default, the proxy server in a Python environment serves any files in a folder named static at the /static path. For example, if your application source contains a file named logo.png in a folder named static, the proxy server serves it to users at subdomain.elasticbeanstalk.com/static/logo.png. You can configure additional mappings as explained in this section.

The solution was to use the default settings and remove the overwrite.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement