TimK
TimK

Reputation: 99

Amazon S3 to store Wagtail media files - server 500 error on Heroku only

I have been following the Using Amazon S3 to Store Wagtail Media Files blog post to set up amazon s3 to store my wagtail media files

This works perfectly on my local development sever (all of the images appear in the S3 bucket as expected). However in deployment on Heroku I get a server 500 error just as the uploader completes and the images are not saved in the S3 bucket. There is no detail in the heroku logs other than this line. Which makes it very difficult to debug. I am not using S3 for my static assets (these are handled by whitenoise. Changing debug to True makes no difference. Any advice greatly appreciated.

2018-08-19T16:56:43.517786+00:00 app[web.1]: 10.7.223.133 - - [19/Aug/2018:16:56:43 +0000] "POST /admin/images/multiple/add/ HTTP/1.1" 500 363 "https://isawebsite.herokuapp.com/admin/images/multiple/add/

enter image description here

github repo

Update: by trying image upload via the django-admin interface rather than wagtail uploader I got a more informative error message. An error occurred (InvalidAccessKeyId) when calling the PutObject operation: The AWS Access Key Id you provided does not exist in our records. I don't understand this because the keys are definitely correct in my .env file and are pushed to heroku config. The keys work locally and in AWS CLI.

Upvotes: 1

Views: 905

Answers (1)

tomd
tomd

Reputation: 1451

We worked this out - the config values in Heroku for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY included surrounding quotes, e.g. 'QWERTY12345' rather than QWERTY12345. It worked locally because python-dotenv strips surrounding quotes from .env files:

https://github.com/theskumar/python-dotenv/blob/master/dotenv/main.py#L43

I've updated the blog post at https://wagtail.io/blog/amazon-s3-for-media-files/ to clarify this.

Upvotes: 3

Related Questions