404to302 for Amazon CloudFront
This repo contains Lambda@Edge code to perform the 404to302 rewriting.
- Build the ZIP file to deploy by running
- Upload the ZIP file to an S3 bucket in region
- Create a CloudFormation stack based on the
404to302.cfn.yamltemplate. Fill in the chosen S3 bucket, and the chosen filename. The stack outputs the ARN of the created Lambda function.
- Configure your CloudFront Distribution to call this Lambda on Origin Response.
- Add a Tag to the Distribution with key
FallbackLocation, and value the URL you want to redirect to. This URL undergoes some substitution; see the top of
index.jsto see what you can use. Typically, you'll want
Optionally, you can use the provided
CloudFormation template to set up an S3 bucket with the 404to302 config.
This will do steps 4 and 5 for you.