moto icon indicating copy to clipboard operation
moto copied to clipboard

Wrong selection of backend when running moto server on EC2

Open trickstyler opened this issue 6 years ago • 3 comments

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.

trickstyler avatar Nov 05 '19 10:11 trickstyler

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.

spulec avatar Nov 21 '19 22:11 spulec

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

trickstyler avatar Nov 27 '19 09:11 trickstyler

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]

spulec avatar Feb 18 '20 01:02 spulec

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

bblommers avatar Jan 27 '24 20:01 bblommers