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
asked 13 days ago98 views
2 Answers
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
answered 13 days ago
profile pictureAWS
EXPERT
reviewed 13 days ago
profile pictureAWS
EXPERT
reviewed 13 days ago
  • 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
answered 13 days ago

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