Using path parameters on static website through Amazon Cloudfront

Viewed 710

I have a static website on S3 and Cloudfront. I'd like to pass through a value to the static site javascript using a path parameter instead of query parameter.

e.g.

mysupersite.com/123

instead of

mysupersite.com?id=123

How I can configure Cloudfront to use the same static files for any id?

1 Answers

You can do this by adding a Lambda@Edge function for the Origin Request event.

By using a Lambda@Edge function you can parse the request and take the id from the path and add it as a query string attribute to the request that will be forwarded to your origin.

By doing this the browser request looks like

example.com/123

But the request forwarded to S3 looks like

example.com?id=123

If you take a look at these examples it should help you to get the idea of how you would use it.

Related