Matthieu Napoli
Matthieu Napoli

Reputation: 49703

Can I serve multiple domains with CloudFront?

Can I implement the following behavior with AWS CloudFront:

https://{id}.example.com/ -> https://{id}.execute-api.us-east-1.amazonaws.com/prod/

I want to make a CloudFront distribution that would simplify the API Gateway domains.

The {id} part is a placeholder, not a specific ID. I want *.example.com to match and redirect to https://*.execute-api.us-east-1.amazonaws.com/prod/ but with the * replaced by the part of the domain that matched.

Upvotes: 1

Views: 934

Answers (2)

James Dean
James Dean

Reputation: 4461

I assume you want the Origin to be as https://{id}.execute-api.us-east-1.amazonaws.com/prod/ rather then giving new location (302) to Client. In this case, you can use lambda@edge to dynamically choose origin and pass the value you want. Here is an example:

https://aws.amazon.com/blogs/networking-and-content-delivery/dynamically-route-viewer-requests-to-any-origin-using-lambdaedge/

Whitelist the HOST header so you can parse the HOST header in the origin request function and add the parsed value in setting origin.

Upvotes: 1

Sumit Kumar
Sumit Kumar

Reputation: 1

Yes, you can do by putting API gateway url with stage as Origin in CloudFront distribution.

Upvotes: 0

Related Questions