2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Chris. So this would mean than the browser would see example.com/123 but the static pages would be retrieved from s3://example.com/ (root folder), which is exactly what I want. I'll try it out now...
OK great, let me know if you need anymore help :)
Works great. Thanks again.
No problem, glad I could help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.