- version 1.2.1: Updated readme.
- version 1.2.0: Updated Node runtime to 16.x
- version 1.3.0: Updated Node runtime to 20.x
A Lambda@Edge function to remove trailing slashes from requests received by your CloudFront distribution.
Designed to assist hosting static websites via S3, ensuring requests to /some/object-identifer/ are resolved to /some/object-identifier correctly
Available on the AWS Serverless Application Repository
- Visit AWS Lambda Console
- Choose 'Create Function'
- Choose 'Browse serverless app repository'
- Search for 'LambdaEdgeRemoveTrailingSlash'
- Tick the checkbox to 'Show apps that create custom IAM roles or resource policies'
- This application will appear in the search results
- Click the application box to view the application
Installation of this function comprises two stages; Installing the application via the Serverless Repository and CloudFront, then configuring and deploying the Lambda@Edge function.
- Ensure your console is currently viewing US-East-1 (N. Virginia) - All Lambda@Edge functions must be deployed in this region, see lambda at edge how it works
- Visit this application on the AWS Serverless Repository (as above)
- Review the SAM Template, Permissions and License as appropriate
- In the 'Application settings' box, choose a CloudFormation Stack name for this application
- Tick the box to 'acknowledge that this app creates custom IAM roles' (see below for details of the IAM Role)
- Click 'Deploy'
AWS will now build a CloudFormation Stack, a Lambda Application and create a new Lambda Function.
- Visit your Lambda functions list in US-East-1 (N. Virginia)
- You'll see the new function that was created by CloudFormation
- Click into the function to edit it
- Choose 'Actions' from the buttons at the top of the console
- Choose 'Deploy to Lambda@Edge'
- Now choose the CloudFront distribution that you wish to apply the function to. Commonly in Static S3/CloudFront website deployments you would have a www and non-www distribution with one redirecting to the other. Choose the distribution which is the final source of your website.
- Change the 'CloudFront Event' setting to 'Viewer request'
- All other settings remain as default
- Tick the 'Confirm deploy' acknowledgement
- Click 'Deploy'
AWS will now deploy the Lambda@Edge function to all Edge locations for your chosen CloudFront distribution. This may take a few minutes.
Once deployed, visit your website. You will find that https://{your-website.com}/path/
redirects as HTTP 301 to https://{your-website.com}/path
(without the trailing slash)
This application creates an IAM Role for the Lambda function. The IAM Role uses only standard AWS resources, namely:
arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- to give the Lambda function basic execution permissions- A Trust Relationship with edgelambda.amazonaws.com - to allow publishing of the Lambda function as Lambda@Edge
If you'd like to reach out to us with any questions you can find our details at sinovi.uk/contact