Redirecting the CloudFront Host Header to the API Gateway

We have a lookup subdomain (*) indicating the CloudFront distribution. Origin is an API gateway.

We need to know the original Host header in the API so that we can route requests.

Just whitelisting the Host header in CloudFront returns an error when accessing the CloudFront distribution via HTTP - apparently because the Gateway API needs a Host header to find out which API to call.

If so, is it possible to forward the Host header through the X-Forwarded-Host from CloudFront to the Gateway API? Or ... is there an alternative way to use wildcard subdomains with an API gateway?

+5
source share
1 answer

This is not exactly the answer to your initial question, but it may be an alternative way to achieve your goals.

Firstly, sharing the CF distribution between all environments (including prod) carries a risk with it - when you need to check CF configuration changes, you will definitely modify dist prod CFs with unverified changes that can have significant consequences.

Secondly, although it’s great if you can test the whole environment at all stages of the CI / CD pipeline, this is not always possible (and CF is especially harmful for it) - therefore, it must find a balance between short feedback cycles and thorough testing.

The solution usually introduces additional steps to your pipeline, where the early stages give quick feedback on the most common problems, and the later stages give slower feedback on the less common problems.

In your case, I would suggest:

  • Deployment deployments do not deploy CF tests aimed directly at the API gateway.
  • Deploying the wizard / By default, DO deploys CF - into an "intermediate" environment - tests target the intermediate CF distribution.
  • Successfully tested releases on Wednesday "intermediate" advance to production

By implementing an intermediate environment, you get quick feedback on the branch lines, but you still have the option of checking things out by cache before entering prod.

If you make changes to the CF configuration, you can make your deployment script dynamically decide whether to include CF in the deployment of the branch from any trigger (perhaps the word “cloudy” is present in the branch name - although this might be a little “magic” for some !), and you can test these changes in the branch before merging with the master for testing in the stage.

+2
source

All Articles