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:
- Branch deployments do not deploy CF - tests target the API Gateway directly
- Master/Default deployments DO deploy CF - to a 'staging' environment - tests target the staging CF distribution
- Successfully tested releases to the 'staging' environment are promoted to production
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.
Host
(i.e. not asX-Forwarded-Host
). Can you post the actual error you receive? Is it just a 500 with no content, or is there a body or error message? May also be worth reviewing the Cloudwatch Logs for the API Gateway for a more detailed error message. – SphygmicHost:
would result in the request never arriving at API Gateway, which expects a single, assigned value inHost
-- so there would be no logs generated there. The question here is how to funnel multiple request host values (wildcard) through to one target, without losing track of the original hostname, by sending it as an alternate header, likeX-Forwarded-Host
, created automatically by CloudFront. – MarmiteX-Forwarded-Host:
(easy to automate, though), or (b) EC2-based proxy between CF and API-GW to copyHost:
toX-Forwarded-Host:
before changingHost:
and sending to API-GW. I have both scenarios in my systems today. – Marmite