Tim
Tim

Reputation: 435

Using path parameters on static website through Amazon Cloudfront

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?

Upvotes: 2

Views: 1596

Answers (1)

Chris Williams
Chris Williams

Reputation: 35188

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.

Upvotes: 2

Related Questions