AWS S3ResponseError 400

时间:2016-08-26 22:51:14

标签: django amazon-web-services amazon-s3 amazon-ec2 awss3transfermanager

我正在尝试将我的Django应用程序设置为AWS。

我的 EC2 配置是Ubuntu 14.04,Apache2,Django 1.8和Python 3.4。

所以我尝试按照本教程将静态文件移动到S3:https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/

在完成以下教程之后,我终于在我的项目中运行'python manage.py collectstatic'并收到错误:

  

boto.exception.S3ResponseError:S3ResponseError:400错误请求

我的S3 Bucket政策如下:

{
"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/*"
        ]
    }
  ]
}

我的COR配置如下:

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

 

在我的'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'

我错过了什么?

更新

~/.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

1 个答案:

答案 0 :(得分:0)

我应该正确设置'〜/ .boto'文件。