question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WhiteNoise + Lambda + Zappa

See original GitHub issue

Hello Guys,

We are using Zappa + Django in AWS Lambda. I really like the idea of using whitenoise, at least for serving our Django admin pages, it sounds to me like a simple solution that does not require a lot of configuration (like similar S3 solutions).

I followed the tutorial and tried the following with no avail:

settings.py
-----------
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

$ zappa manage production collectstatic
...
error stack
...
Read-only file system: '/var/task/staticfiles'

Well makes sense, from what I know the only writeable directory is /tmp so I tried

STATIC_URL = '/static/'
STATIC_ROOT = /tmp/staticfiles'
...

$ zappa manage production collectstatic

61 static files copied to '/tmp/staticfiles'.
[END] RequestId: 4b9c1c60-ddc4-11e7-a97d-e193c05b0571
[REPORT] RequestId: 4b9c1c60-ddc4-11e7-a97d-e193c05b0571
Duration: 77.20 ms
Billed Duration: 100 ms
Memory Size: 512 MB
Max Memory Used: 44 MB

When go to my-site.com/admin I’m getting 403 when trying to retrieve the resources which again makes sense.

So what is the correct way to implement it ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
efimerdlerkravitzcommented, Dec 11, 2017

Using WhiteNoise, Zappa and Django

  • Assuming you are using a production profile in zappa_settings.json
  • Under settings.py add
STATIC_URL = '/production/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
WHITENOISE_STATIC_PREFIX = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  • Run locally ./manage.py collectstatic
  • Run zappa update
2reactions
ptrhckcommented, Apr 16, 2019

Did you try your config using the STATIC_HOST with cloudfront as CDN?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using WhiteNoise for static files - Serverless Django with Zappa
We are mostly following the Using WhiteNoise with Django guide here, but with some specific changes for the Lambda environment.
Read more >
whitenoise with zappa, push static files to s3? - Stack Overflow
manually push WhiteNoise's static content to an S3 bucket and have Cloudfront have this as an origin, and dont upload the 100MB to...
Read more >
Hosting Static Files - Guide to using Django with Zappa
Normally, Django treats URL requests as an opportunity to run python code. And the python code may have complex logic. But there is...
Read more >
Sanjay Siddhanti on Twitter: "Zappa is a free, open-source ...
I wrote a post about deploying Python web apps on Lambda. ... I recommend using Zappa to handle all the setup instead. 3/...
Read more >
What should I keep in my mind before deploying my Django ...
Zappa's default deployment adds this, but you could make it more frequent. Don't serve static files through lambda even with whitenoise, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found