Skip to content
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

Bug: sam local start-lambda not work in SDK BOTO3 #3985

Closed
b-y-f opened this issue Jun 21, 2022 · 5 comments
Closed

Bug: sam local start-lambda not work in SDK BOTO3 #3985

b-y-f opened this issue Jun 21, 2022 · 5 comments
Labels
platform/mac/arm Issues related to Arm64

Comments

@b-y-f
Copy link

b-y-f commented Jun 21, 2022

Description:

So strange after run sam local start-lambda, I can invoke lambda with cli aws lambda invoke --function-name "myFunctionName" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl --cli-binary-format raw-in-base64-out --payload '{"xx":"xx"}' out.txt, It gives 200 code.

But when I use boto3 with code like below

lambda_client = boto3.client(
    "lambda",
    endpoint_url="http://127.0.0.1:3001"
    )
res = lambda_client.invoke(
    FunctionName="myFunctionName", Payload=json.dumps({"xxx": "xxx"})
)

Error like below raised.

PLUS: after that, I uploaded the lambda I want to test to cloud and used boto.client('lambda') and invoked without any problem.

Steps to reproduce:

  • No 3rd party, just vscode + aws toolkits
  • everything follows instruction from aws doc.
  • Dev under mini conda env

Observed result:

START RequestId: 2c6dcc30-1b2e-4af6-8b1f-26658d0eb0f1 Version: $LATEST
[ERROR] EndpointConnectionError: Could not connect to the endpoint URL: "http://127.0.0.1:3001/2015-03-31/functions/fetchGeoDataB    raise EndpointConnectionError(endpoint_url=request.url, error=e)ponset_exception
{"errorMessage": "Could not connect to the endpoint URL: \"http://127.0.0.1:3001/2015-03-31/functions/fetchGeoDataByICP/invocations\"", "errorType": "EndpointConnectionError", "requestId": "2c6dcc30-1b2e-4af6-8b1f-26658d0eb0f1", "stackTrace": ["  File \"/var/task/app.py\", line 15, in lambda_handler\n    res = lambda_client.invoke(\n", "  File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n", "  File \"/var/runtime/botocore/client.py\", line 705, in _make_api_call\n    http, parsed_response = self._make_request(\n", "  File \"/var/runtime/botocore/client.py\", line 725, in _make_request\n    return self._endpoint.make_request(operation_model, request_dict)\n", "  File \"/var/runtime/botocore/endpoint.py\", line 104, in make_request\n    return self._send_request(request_dict, operation_model)\n", "  File \"/var/runtime/botocore/endpoint.py\", line 138, in _send_request\n    while self._needs_retry(attempts, operation_model, request_dict,\n"END RequestId: 2c6dcc30-1b2e-4af6-8b1f-26658d0eb0f1
REPORT RequestId: 2c6dcc30-1b2e-4af6-8b1f-26658d0eb0f1  Init Duration: 0.14 ms  Duration: 9938.23 ms    Billed Duration: 9939 msMemory Size: 128 MB      Max Memory Used: 128 MB
, "  File \"/var/runtime/botocore/endpoint.py\", line 254, in _needs_retry\n    responses = self._event_emitter.emit(\n", "  File \"/var/runtime/botocore/hooks.py\", line 357, in emit\n    return self._emitter.emit(aliased_event_name, **kwargs)\n", "  File \"/var/runtime/botocore/hooks.py\", line 228, in emit\n    return self._emit(event_name, kwargs)\n", "  File \"/var/runtime/botocore/hooks.py\", line 211, in _emit\n    response = handler(**kwargs)\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 183, in __call__\n    if self._checker(attempts, response, caught_exception):\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 250, in __call__\n    should_retry = self._should_retry(attempt_number, response,\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 277, in _should_retry\n    return self._checker(attempt_number, response, caught_exception)\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 316, in __call__\n    checker_response = checker(attempt_number, response,\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 222, in __call__\n    return self._check_caught_exception(\n", "  File \"/var/runtime/botocore/retryhandler.py\", line 359, in _check_caught_exception\n    raise caught_exception\n", "  File \"/var/runtime/botocore/endpoint.py\", line 201, in _do_get_response\n    http_response = self._send(request)\n", "  File \"/var/runtime/botocore/endpoint.py\", line 270, in _send\n    return self.http_session.send(request)\n", "  File \"/var/runtime/botocore/httpsession.py\", line 438, in send\n    raise EndpointConnectionError(endpoint_url=request.url, error=e)\n"]}%                                 

Expected result:

It should run my lambda and return something not EndpointConnectionError

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MAC M1
  2. If using SAM CLI, sam --version: version 1.52.0
  3. AWS region:ap-southeast-2

Add --debug flag to any SAM CLI commands you are running

@b-y-f b-y-f added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/bug labels Jun 21, 2022
@jfuss
Copy link
Contributor

jfuss commented Jun 21, 2022

Moving to correct repo.

@jfuss jfuss transferred this issue from aws/serverless-application-model Jun 21, 2022
@mildaniel
Copy link
Contributor

Hey @b-y-f, I tried reproducing this issue on a non-M1 Mac and wasn't able to. I will try again on an M1 machine to see if the behaviour is different.

@mildaniel mildaniel added the platform/mac/arm Issues related to Arm64 label Jun 22, 2022
@b-y-f
Copy link
Author

b-y-f commented Jun 26, 2022

Hey @b-y-f, I tried reproducing this issue on a non-M1 Mac and wasn't able to. I will try again on an M1 machine to see if the behaviour is different.

Thank you

@hawflau hawflau added the stage/needs-investigation Requires a deeper investigation label Jun 29, 2022
@jfuss
Copy link
Contributor

jfuss commented Jul 12, 2022

@b-y-f This has to do with docker networking. http://127.0.0.1:3001 doesn't resolve to your machine's localhost but the docker machine's localhost. Since sam local start-lambda is running on your machine, this is why you get a response using the CLI but fails within the container. You can follow #510 (comment) for details.

@jfuss jfuss removed type/bug stage/needs-investigation Requires a deeper investigation stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jul 12, 2022
@b-y-f
Copy link
Author

b-y-f commented Jul 25, 2022

Thankyou

@b-y-f b-y-f closed this as completed Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/mac/arm Issues related to Arm64
Projects
None yet
Development

No branches or pull requests

5 participants