Reputation: 323
I am using django-storages to upload static files to AWS S3. I followed the tutorials and was able to successfully upload and retrieve the static files for the admin page.
I then created a static directory in my django project, added some bootstrap files and ran collectstatic. I can see that the bootstrap files were all successfully stored to my S3 bucket. However, when I try to run my app (both locally and on Heroku), the bootstrap files fail with a get 403 forbidden error.
The admin files are stored in an admin folder within the same S3 bucket and are retrieved with no problems. What might account for this discrepancy? I am new to s3, so perhaps I am doing something wrong there.
I have confirmed that my AWS keys are working.
My settings.py are as follows:
AWS_STORAGE_BUCKET_NAME = 'punchline-app'
AWS_PRELOAD_METADATA = True
STATIC_ROOT = ''
STATIC_URL = 'https://punchline-app.s3.amazonaws.com/static/'
ADMIN_MEDIA_PREFIX = 'https://punchline-app.s3.amazonaws.com/static/admin/'
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_DIR,"static"),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
Upvotes: 1
Views: 5477
Reputation: 644
Do you have your access keys sorted out like this in your settings.py file?
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
And did you set your env variables in heroku? e.g.
heroku config:set AWS_ACCESS_KEY_ID='<put your key here>'
Upvotes: 1