Ken Shirriff
Ken Shirriff

Reputation: 1679

S3 web page redirect: can't set x-amz-website-redirect-location property

I want to use redirects with S3 webpages. The AWS Configuring a Web Page Redirect document says to set the x-amz-website-redirect-location property, but this doesn't seem to be settable. If I try to set the key, S3 prefixes the key with x-amz-meta- (making it a user-defined metadata) and the modified key doesn't cause a redirect.

I set the metadata with the aws CLI:

 aws s3api copy-object --copy-source static.righto.com/zero \
--bucket static.righto.com --key bar \
--metadata x-amz-website-redirect-location=http://righto.com/bar \
--metadata-directive REPLACE

but when I look in the S3 console, the metadata name has been prefixed and the redirect is ignored.

The same thing happens if I use the Python API:

s3.Bucket('static.righto.com').put_object(Key=src, Body='',
  Metadata={'x-amz-website-redirect-location': dst})

And if I try to set the x-amz-website-redirect-location metadata key in the S3 console, I get the error "User-defined metadata keys must start with x-amz-meta-."

Did x-amz-website-redirect-location become unsupported?

If I set "Website Redirect Location" metadata in the console then redirects work, so issue isn't the redirect endpoint problems in this answer. But I can't use "Website Redirect Location" as a metadata key in the API.

Upvotes: 4

Views: 5373

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179084

Use --website-redirect-location <value>.

http://docs.aws.amazon.com/cli/latest/reference/s3api/copy-object.html

x-amz-website-redirect-location is not user metadata (x-amz-meta-*), which is what the --metadata option is used for.

Upvotes: 7

Related Questions