AWS: The bucket you are attempting to access must be addressed using the specified endpoint.

Автор: | 17/10/2016

aws-logo-square-02Во время работы с корзинами S3AWS CLI сообщает об ошибке:

$ aws s3api get-bucket-policy --bucket profile-staging.domain.com

A client error (PermanentRedirect) occurred when calling the GetBucketPolicy operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: profile-staging.domain.com.s3.amazonaws.com
You can fix this issue by explicitly providing the correct region location using the --region argument, the AWS_DEFAULT_REGION environment variable, or the region variable in the AWS CLI configuration file.  You can get the bucket's location by running "aws s3api get-bucket-location --bucket BUCKET".

Ошибка возникает из-за различных Availability Zone в настройках CLI и корзины.

Проверяем настройки региона для CLI:

$ aws configure --profile TAG
AWS Access Key ID [****************YFJQ]: 
AWS Secret Access Key [****************+4sG]: 
Default region name [us-east-1]: 
Default output format [None]:

И находим зону корзины:

$ aws s3api get-bucket-location --bucket profile-staging.domain.com
{
    "LocationConstraint": "eu-west-1"
}

Обновляем дефолтную зону для CLI:

$ export AWS_DEFAULT_REGION=ue-west-1

Проверяем:

$ aws s3api get-bucket-policy --bucket profile-staging.domain.com
{
    "Policy": "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1473410121150\",\"Statement\":[{\"Sid\":\"Stmt1473410112239\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"arn:aws:s3:::profile-staging.domain.com/*\"}]}"
}

Либо – используем параметр --region:

$ aws --region eu-west-1 s3api get-bucket-policy --bucket profile-staging.domain.com
{
    "Policy": "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1473410121150\",\"Statement\":[{\"Sid\":\"Stmt1473410112239\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"arn:aws:s3:::profile-staging.domain.com/*\"}]}"
}

Готово.