S3 website-redirect-location not redirecting

0

Hi, I'm having some trouble getting redirects working using the x-amz-meta-website-redirect-location property of objects in an S3 bucket. The bucket is configured for static website hosting with public access enabled.

When I create an object using the API (either via the CLI or using the Javascript SDK), setting the website-redirect-location property to a valid URL, the redirect doesn't seem to work.

In the management console I can see that the x-amz-meta-website-redirect-location key is set in the object metadata correctly. When making an HTTP request I get a 200 response instead of a 301, but I do see the x-amz-website-redirect-location header in the response, it just doesn't seem to use it to generate a redirect response.

This is the style of command I've tried using the CLI:

aws s3api put-object --website-redirect-location "https://example.com/" --bucket bucket_name --key object_name

Can anyone help?

Thanks.

David B
asked 22 days ago296 views
1 Answer
0
Accepted Answer

Hello,

We have tested the same scenario in our lab environment where an object was uploaded to a bucket which has static website hosting enabled. While uploading, x-amz-meta-website-redirect-location header was passed. In the management console, the metadata was correctly set on the object as you have mentioned.

However, while the object was accessed using the static website endpoint, we were successfully redirected to the website endpoint provided in the x-amz-meta-website-redirect-location header.

Please note that redirection only works if you have enabled the Static Website hosting and you are accessing the objects via the Static website endpoint. If you are accessing it directly on the S3 bucket URL or S3 API the redirection will not work. So please ensure that you are accessing the object via static website endpoint.

[+] Working with object metadata - System-defined object metadata - https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html#SysMetadata

If you have any further queries, please feel free to reach out to AWS Support along with your specific use-case and details, and we would be happy to assist you further.

[+] Creating support cases and case management - https://docs.aws.amazon.com/awssupport/latest/user/case-management.html

AWS
SUPPORT ENGINEER
answered 21 days ago
  • Hi, thanks for your time. I neglected to say I was using the static website endpoint, but thanks for the clear answer. It seems in this case I need to reach out to AWS Support for more help.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions