Wrong selection of backend when running moto server on EC2
I'm running moto on an EC2 VM. I got another system running also as an EC2 VM which calls moto. when trying to create a new stack (CloudFormation) i'm getting a NotImplemented Error.
After plenty of debugging - i found that moto actually infers the backend from the host name. Reference: moto/server.py line: 121
Is there a reason for this? I'm not really sure this is true to the normal behavior of AWS
Suggestion: completely remove this check. i'd be happy to do create a PR if that's agreed.
If one is running multiple backends at the same time, we need some way to know which service the user is requesting. The host header seemed like the best option available, but I'm open to alternatives.
I think we should switch to the authorization header OR Add another custom header to the request (available via the SDK) that signals which backend you want to handle the request - could be used in cases where you run the server on an actual EC2
We also look at the authorization header where possible: https://github.com/spulec/moto/blob/master/moto/server.py#L61-L102
There may be more there we can do to extend that.
I would be okay adding logic to the server to also check for another custom header. Ideally, we would follow a similar pattern as the Host header so it could be as simple a change as
host = environ["HTTP_HOST"].split(":")[0]
->
host = environ.get("HTTP_HOST", "MOTO_SERVER").split(":")[0]
It's been a while, but this should now work as of Moto v5 - Moto no longer relies on the HTTP_HOST header.
Please see the release accouncement (with all breaking changes) here: https://github.com/getmoto/moto/issues/7198