301 Moved Permanently After S3 Uploading

301 Moved Permanently after S3 uploading


<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access
must be addressed using the specified endpoint. Please send all future requests to
this endpoint.</Message></Error>

This is a frequently encountered issue: You are trying to access a bucket in region us-west-1, however, for legacy reasons the default Amazon S3 region in most/all AWS SDKs is US Standard, which automatically routes requests to facilities in Northern Virginia or the Pacific Northwest using network maps (see Regions and Endpoints for details).

Therefore you simply need to specify the endpoint of your buckets region explicitly before using the S3 API, e.g. for us-west-1:

  config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:region => 'us-west-1'
:endpoint => 'https://s3-us-west-1.amazonaws.com/'
}

Uploading to a Signed AWS S3 Put URL returns a Permanent Redirect

Your bucket is in the US Standard region.

You need to generate a pre-signed upload URL using the US Standard endpoint.

Django collectstatic result in S3ResponseError: 301 Moved Permanently

I figured out that the problem is because an update to the Django module django-storages that I used. In the update they have added a default value to S3BotoStorage.host by assigning it in the following way:

host = setting('AWS_S3_HOST', S3Connection.DefaultHost)

What happens is that the host is automatically set to s3.amazonaws.com and because it already have a host set when it creates the connection with boto (AWS official python-package), it never uses the DefaultHost = "s3-eu-west-1.amazonaws.com" that I added in my EuropeConnection-class.

The way to solve this problem is to set django-storages settings value AWS_S3_HOST (New) in your settings.py.

AWS_S3_HOST = "s3-eu-west-1.amazonaws.com"

Amazon S3 object redirect

Within the last month, this functionality has just been added.

You can find the API documentation here:

http://docs.amazonwebservices.com/AmazonS3/latest/dev/how-to-page-redirect.html

When you PUT your object, you need to set the x-amz-website-redirect-location key against that object to the 301 redirect that you wish to use.

You can also use the console.

Sample Image

PermanentRedirect error while uploading to S3 bucket with aws-sdk-java

Instead of s3-us-west-2.amazonaws.com/<my-bucket-name> you should put <my-bucket-name>.



Related Topics



Leave a reply



Submit