0

I'm trying to set up my Django Application to AWS.

My EC2 configurations is Ubuntu 14.04 , Apache2 , Django 1.8 and Python 3.4.

So I tried to move static files to S3 following this tutorial : https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/

After following tutorial, I finally run 'python manage.py collectstatic' in my project and got an error :

boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request

My S3 Bucket policy is below :

{
"Version": "2008-10-17",
"Statement": [
    {
        "Sid": "PublicReadForGetBucketObjects",
        "Effect": "Allow",
        "Principal": {
            "AWS": "*"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::MY_BUCKET_NAME/*"
    },
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "MY_USER_ARN"
        },
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::MY_BUCKET_NAME",
            "arn:aws:s3:::MY_BUCKET_NAME/*"
        ]
    }
  ]
}

My COR Configuration is below :

<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>

In my 'settings.py' :

INSTALLED_APPS = ( ... , 'storages', ...)

# FOR AWS
AWS_STORAGE_BUCKET_NAME = 'MY_BUCKET_NAME'
AWS_ACCESS_KEY_ID = 'MY_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = 'MY_SECRET_ACCEESS_KEY'

AWS_S3_SECURE_URLS =False
AWS_QUERYSTRING_AUTH = False
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = "http://%s/" % AWS_S3_CUSTOM_DOMAIN
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

What am I missing to make it?

UPDATE

~/.aws/config

[default]
aws_secret_access_key = MY_SECRET_ACCESS_KEY_FROM_MY_SECURITY_CREDENTIALS
region = ap-northeast-2
output=text
aws_access_key_id = MY_ACCESS_KEY_ID_FROM_MY_SECURITY_CREDENTIALS

~/.aws/credentials

[default]
aws_access_key_id=MY_ACCESS_KEY_ID_FROM_MY_SECURITY_CREDENTIALS
aws_secret_access_key=MY_SECRET_ACCESS_KEY_FROM_MY_SECURITY_CREDENTIALS
region = ap-northeast-2
halfer
  • 19,824
  • 17
  • 99
  • 186
LKM
  • 2,410
  • 9
  • 28
  • 53
  • Can you paste ~/.aws/config or ~/.aws/credentials ? – Piyush Patil Aug 27 '16 at 00:51
  • @error2007s I updated it, The same access key id and secret access key created at MY SECURITY CREDENTIALS are included in '~/.aws/config' and '~/.aws/credentials' – LKM Aug 27 '16 at 18:02
  • Add region = ap-northeast-2 in ~/.aws/credentials and then check – Piyush Patil Aug 27 '16 at 18:16
  • @error2007s I did but when running 'python manage.py collectstatic', it shows the same error message. Anyway, thank you for your kind reply! – LKM Aug 27 '16 at 18:36
  • I took a look at this post : http://stackoverflow.com/questions/27400105/using-boto-for-aws-s3-buckets-for-signature-v4 but after changing 'AWS_S3_CUSTOM_DOMAIN' in my 'settings.py', from '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME --> '%s.s3.ap-northeast-2.amazonaws.com' % AWS_STORAGE_BUCKET_NAME , but unfortunately, it doesn't work either – LKM Aug 27 '16 at 18:41
  • Try changin the url to exact s3 bucket URL – Piyush Patil Aug 27 '16 at 18:42

1 Answers1

0

I should have set '~/.boto' file correctly.

LKM
  • 2,410
  • 9
  • 28
  • 53