Environment variables to identify Lambda runtime environment
See original GitHub issueThis is a followup question to the PR “Feature: Custom cloudformation resources” and perhaps related to the issue “switch server mode to proxies”.
The lambda submitted as a test case for that PR issued API calls to the EC2 service. Part of the fix required the lambda to specify the endpoint_url to any boto3 services it invoked, i.e.:
ec2 = boto3.client("ec2", endpoint_url="http://host.docker.internal:5000")
That lambda (or the test case) can be invoked in different environmentss:
- against AWS itself (no endpoint_url value needed),
- when LocalStack and moto are started up from the command line (the endpoint_url of “http://host.docker.internal:5000” works great here),
- when LocalStack and moto are started within a docker container and then start up the lambda within that container.
I have not been able to figure out the appropriate endpoint_url for the last case. I also don’t have a way to determine which of the three situations I’m in. If I relied on LocalStack, I could use the environment variable LOCALSTACK_HOSTNAME
to identify when I’m running against AWS versus localstack. However, if I only use moto endpoints, I don’t have an equivalent environment variable.
Since my test case uses Terraform, I’ve tried passing variables declared in the Terraform modules, but I still can’t distinguish between the three scenarios and I’m trying to avoid hardcoding the moto port.
Do you have any suggestions as to how I might solve this problem? I could live with hardcoding the moto port if I knew the appropriate endpoint for the third case above and if I had a way of knowing which endpoint I should be using.
Issue Analytics
- State:
- Created 2 years ago
- Comments:31 (17 by maintainers)
This is now all available as of moto >= 3.0.2.dev7. The documentation on all of the configuration options can be found here: http://docs.getmoto.org/en/latest/docs/services/lambda.html
Amazing, this is an awesome feature! Thanks @bblommers!