-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch server mode to proxies #1108
Comments
@thehesiod This sounds like a great idea to me. |
based on research in #1317 it seems like one could either support this on the client side via Config.proxies, or |
Hmm, I "think" if we do https_proxy, we'd need to serve moto on https, and also trust whatever CA we're using in lambdas. If we only listen on http, we'll need to patch whatever library in use to default use_ssl=False |
I ended up here from #1317, and getting an error when trying to contact services inside lambda: Unit test@moto.mock_lambda @moto.mock_iam @moto.mock_secretsmanager def test_lambda(self): # prep the environment self.config_path = '/HelloWorld' secretsmanager = boto3.client('secretsmanager') secretsmanager.create_secret( Name=self.config_path, SecretString='{}', ) iam = boto3.client('iam') role = iam.create_role( RoleName='PythonExampleRole', AssumeRolePolicyDocument='{}', Path='/', ) lambdaa = boto3.client('lambda') lambdaa.create_function( FunctionName='HelloWorld', Description='blurg', Runtime='python3.8', Role=role['Role']['Arn'], Code={ 'ZipFile': self._build() }, Handler='src.hello_world.HelloWorldHandler', Environment={'Variables': {'CONFIG_PATH': self.config_path}}, Timeout=3, MemorySize=128, Publish=True, ) lambdaa.invoke( FunctionName='HelloWorld', InvocationType='RequestResponse', Payload='', ) and the error
My $0.02; If moto exposes the ability to invoke a lambda locally, it should automatically proxy the container. It's pretty much a guarantee that the user will be attempting to contact mocked services from within the lambda container. I think this annoyance would be solved by this issue. |
moto >= 4.2.5.dev12 now contains a proxy! It contains a SSL certificate generator, but for SDK's to trust these certificates, the SDK needs to be configured to use the certificate bundle that comes with Moto. Documentation on how to get started and configure this all: |
@bblommers , that's great news! I am trying to invoke a Lambda function to access my mock dynamoDB, so in order to do so, I am using the moto_proxy
And whenever I call my mock tests, it creates the dynamoDB and lambda function without issues, however, whenever I try to reach the dynamoDB via the proxy server, it just keeps hanging and hanging, and nothing ever reaches my server. Code snippet below:
From my understanding, the lambda function, when invoked, it runs within a container (i.e. not being able to reach the localhost that started it), but I thought the moto proxy would be helping specifically those scenarios. Do you have any tips? Thanks |
Hi @b-guerra, the proxy would have to be run on |
Thanks for the quick reply @bblommers!!
I changed the proxy inside the code to 0.0.0.0, Here is the script invoking the lambda
And here is the lambda function
However, the error I am getting are still the same one:
Do you have any idea why? |
That sounds like you're connecting to the real AWS, @b-guerra. Moto only times out after 5 minutes. I've created an example test repro to show that it does work. The biggest difference, from what I can see, is that I didn't configure the proxy inside the Lambda handler. Because Moto already knows that it's running the Proxy, it automatically sets the required environment variables for every Lambda-invocation. So no further configuration is necessary. |
First of all, thank you so much for the help @bblommers! That is amazing man!! it is working now like a charm. I wanted to ask a question, is it possible to create a API Gateway that has Cognito authentication, and invoke a lambda function making a call to the API all under moto? Thank you! |
Happy to help @b-guerra! Invoking a Lambda via the API isn't supported yet, and authorizers aren't invoked either. I'm not against the idea of implementing this in Moto though, so feel free to open a feature request is this is something you want. |
botocore just added support for specifying proxy servers. It seems like it would be better to switch to using a single proxy, then specifying the endpoint_url, as it would require fewer changes on the client, and could support multiple services from a single endpoint. Could also solve the url parsing issue with aws region(s).
thoughts?
The text was updated successfully, but these errors were encountered: