How to redirect a request to an existing S3 object having the `s3.amazonaws.com` urls

0

I had created a bucket to store customer images on S3 quite some time ago. Our customer emails contain s3 urls of the format

https://s3.amazonaws.com/<bucketName>/<fileName>

so that the customers can download their images if needed. Im planning to move all these objects to a new bucket. But i'm worried that the existing urls sent out in the emails will no longer work. So i've been searching for a way to redirect requests that reference any object in my old bucket.

So far i've only seen solutions for objects that are referenced using the static web endpoint of the bucket (urls that look like the one below).

http://mybucket.s3-website-us-east-1.amazonaws.com/image.png

I was wondering if there is a way to redirect requests that reference objects through urls like the one mentioned below.

https://s3.amazonaws.com/mybucket/image.png.

Also, static website hosting is not switched on for this bucket in case you are wondering.

suhail
已提問 1 個月前檢視次數 156 次
2 個答案
1

S3 buckets themselves don't offer built-in redirection capabilities. Below are two common approaches to achieve redirection for S3 objects with s3.amazonaws.com URLs:

Using Amazon CloudFront: CloudFront is a content delivery network (CDN) service offered by AWS. You can create a CloudFront distribution with your S3 bucket as the origin. CloudFront allows configuring behaviors within the distribution to set redirects for specific request paths.

Using Amazon Route 53: Route 53 is a DNS (Domain Name System) service by AWS. You can set up a Route 53 hosted zone for your custom domain and configure it to point to the S3 bucket website endpoint. Additionally, you can create a redirect rule within Route 53 to redirect requests for specific paths to your desired destination.

Hope it helps to an extent.

profile pictureAWS
akad
已回答 1 個月前
profile pictureAWS
專家
已審閱 1 個月前
profile pictureAWS
專家
已審閱 1 個月前
  • The CloudFront approach sounds good. Will try this solution out asap and share my findings here

1

Hi, I don't think there is a simpler way of doing the redirects without enabling S3 static website hosting on the S3 bucket. You may look into using CloudFront with Lambda@Edge to handle redirects to see if it achieves your use case.

https://aws.amazon.com/blogs/networking-and-content-delivery/handling-redirectsedge-part1/

psp
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南