1

I'm trying to upload all the Django media files (uploaded from the admin panel) to Amazon S3. So settings file look something like this :

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'tastypie',
'core',
'advertisment',
'storages',

)

  DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
  AWS_ACCESS_KEY_ID = 'xxx' 
  AWS_SECRET_ACCESS_KEY = 'xxx'
  AWS_STORAGE_BUCKET_NAME = 'media'
  MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME

and when I try to upload a file from the admin panel, i get the following error:

S3ResponseError: 403 Forbidden

I checked this answer but still didn't help

Community
  • 1
  • 1

1 Answers1

2

Have you installed boto, as django-storage has a dependency on boto?

Then you will have to add the following into your settings.py

import os

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('S3_BUCKET_NAME')

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

STATIC_URL = 'http://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

Then your cache will be stored on AWS S3 itself.

I hope it helps

Note: for security reasons its a good idea to add your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables instead of just writing them down in setting.py directly.

Jonathan
  • 2,728
  • 10
  • 43
  • 73
  • Yes I do have Boto installed and I still have the same problem. After spending few hours trying to figure it out, I think the issue is when boto tries to get the bucket key. Please review my edit in the original post. –  Oct 18 '12 at 17:08
  • i just used this setting. i confirmed it is working for django 1.6. thanks so much! – user2673206 Aug 14 '14 at 06:59