S3 content redirects for multiple files


I am aware of how to redirect s3 bucket items using the metadata, but this works only for files that exist. Our developers archived and deleted over 500 files as a routine process and asked to have them redirected.

I have been looking for various solutions on how to resolve the dilemma of applying a redirect to the now missing content to another URL. I have read how to use advanced conditional redirects but it indicates that there's a limit of 50 items maximum that can be applied to the s3 bucket properties on the static web hosting. I'm trying to understand if that's 50 specific rules or 50 items objects that can have multiple redirects using a conditional. Would one behavior with 550+ removed items redirecting elsewhere (new url) count as one object, I've read elsewhere this doesn't work well. and is there any notable performance or impact in approaching it in this method?

I know its possible to create redirects in cloudfront by adding a behavior and developing a script to negotiate all the redirects similar to the above-mentioned approach.

asked 8 months ago233 views
1 Answer

If you're already using CloudFront, you can use Lambda@Edge, which lets you run Lambda functions to customize content AWS delivers through CloudFront. You can store the origin and destination URL in a simple map and use simple match and replace functions to process redirects at the edge locations.

Remember that the Lambda@Edge needs to be deployed in us-east-1 and will record logs in the region from which the user accessed it.

Here are some links that are a good reference for what you're trying to build:

If the answer is helpful, please click "Accept Answer" and upvote it.

profile picture
answered 8 months ago
profile picture
reviewed 2 months ago
  • Perhaps thats something the developers should have presented to you as the solution as they should be aware of the setup

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