Reputation: 7448
Although I have file uploads working fine in development, I can't get them to work in production with AWS S3. I'm currently getting 403 errors:
S3ResponseError: 403 Forbidden
I can see in my AWS IAM user access key ID that I get a last access recorded when the django app tried to connect.
However when I test the credentials with:
>>> import boto
>>> s3 = boto.connect_s3('access_key', 'secret_key')
>>> bucket = s3.get_bucket('mybucket')
then I also get a 403 forbidden access error, but for some reason the last access record doesn't appear in the AWS IAM dahboard, which makes me think that test isn't working for some reason?
common.py settings:
MEDIA_ROOT = str(APPS_DIR('media'))
MEDIA_URL = '/media/'
production settings:
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
AWS_AUTO_CREATE_BUCKET = True
from storages.backends.s3boto import S3BotoStorage
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
AWS environment vairables are setup in heroku.
upload done via:
class Bill(models.Model):
service = models.ForeignKey(UserService
bill = models.FileField(upload_to='bills', validators=[validate_file_extension])
Upvotes: 0
Views: 411
Reputation: 770
date ; sudo service ntp stop ; sudo ntpdate -s time.nist.gov ; sudo service ntp start ; date
run this command once, if signature is invalid then AWS throws a 403. I had the same issue earlier.
Upvotes: 1