We have a wildcard(*) subdomain pointing to a CloudFront distribution. The origin is API Gateway.
We need to know the original Host
header within API Gateway so we can route the requests.
Simply whitelisting the Host
header in CloudFront returns an error when accessing the CloudFront distribution via HTTP - presumably because API Gateway needs the Host
header to know which API to invoke.
If this is the case, is it possible to forward the Host
header via X-Forwarded-Host
from CloudFront to the API Gateway? Or... is there an alternative way to use wildcard subdomains with API Gateway?
This isn't quite an answer to your original question, but it might be an alternative way of achieving your goals.
Firstly, sharing a CF distribution between all environments (including prod) carries risk with it - when you need to test a change to the CF configuration you will necessarily be modifying the prod CF dist with untested changes which could have significant consequences.
Secondly, while it's wonderful if you can test the whole environment at all stages in a CI/CD pipeline, it's not always possible (and CF is particularly bad for it) - so it's about finding a balance between short feedback cycles and thoroughness of testing.
The solution is usually to introduce extra stages to your pipeline, where the early stages give rapid feedback on the most common problems, and later stages give slower feedback on less frequent problems.
In your case, I'd suggest:
By introducing the staging environment, you get rapid feedback on branch builds, but you still have the opportunity to test things behind the cache before going into prod.
If you are making changes to the CF configuration, you could make your deployment script dynamically decide to include CF in the branch deployment off some trigger (perhaps the presence of the word 'cloudfront' in the branch name - although that could be a bit 'magical' for some!) and you could test those changes on the branch before merging to master for testing in staging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With