Michael Wiles
Michael Wiles

Reputation: 21186

How to know the CNAME that was used to access a cloudfront end point when at the origin of the cloudfront

So I have a cloudfront distribution which routes to an api gateway end point - which in turn routes to lambda.

Then I have a few cnames that can be used to reach this cloud front.

How do I retrieve the original domain that was used to access the cloud front in the api gateway and/or lambda.

I'm hoping there's some header that cloudfronts adds that will indicate the domain that the request came through on.

Upvotes: 1

Views: 287

Answers (1)

James Dean
James Dean

Reputation: 4421

From the description, it seems like you have a setup like: CloudFront(CNAME) --> API gateway --> lambda Is it correct ?

HOST header is a way but if you're API gateway is Edge optimized, you can't do that because API gateway in edge optimized mode uses CloudFront at backend.

The ways to detect the Original CNAME:

  1. CloudFront access logs (Field 16 x-host-header)

  2. Use Lambda@edge Viewer request to parse the HOST header and inject a customer header and the value of HOST header to it, since CloudFront forwards the custom header to origin default, you should be able to see the custom header in API gateway or Lambda.

Upvotes: 1

Related Questions