2

I'm trying to run Amazon lambda locally and I cannot. Deploying and running through AWS works fine. I have installed AWS plugin for IntelliJ IDEA, but it looks like problem is not in the idea, as I'm getting the same error with standalone sam call. I have installed docker on Windows and can run docker ps in command line.

I'm running:

sam local start-api
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2021-11-30 15:14:04  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking helloworld.App::handleRequest (java11)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-java11:rapid-1.36.0-x86_64.

Mounting ...aws_idea\.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated inside runtime container
No response from invoke container for HelloWorldFunction
Invalid lambda response received: Lambda response must be valid json
2021-11-30 15:14:46 127.0.0.1 - - [30/Nov/2021 15:14:46] "GET /hello HTTP/1.1" 502 -
2021-11-30 15:14:48 127.0.0.1 - - [30/Nov/2021 15:14:48] "GET /favicon.ico HTTP/1.1" 403 -
Terminate batch job (Y/N)? y

sam local invoke HelloWorldFunction --no-event
Invoking helloworld.App::handleRequest (java11)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-java11:rapid-1.36.0-x86_64.

Mounting ...aws_idea\.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated inside runtime container
No response from invoke container for HelloWorldFunction

When the start-api command is invoked, there is no docker container running (docker ps returns nothing).

When running the same on Linux, I'm getting:

sam local invoke HelloWorldFunction --no-event
Invoking helloworld.App::handleRequest (java11)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-java11:rapid-1.36.0-x86_64.

Mounting /home/user/aws/HelloWorld/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 72ed4b81-ef43-4181-a8ee-a159f8993352 Version: $LATEST
END RequestId: 72ed4b81-ef43-4181-a8ee-a159f8993352
REPORT RequestId: 72ed4b81-ef43-4181-a8ee-a159f8993352  Init Duration: 0.23 ms  Duration: 3054.35 ms    Billed Duration: 3055 ms        Memory Size: 512 MB   Max Memory Used: 512 MB
{"statusCode":200,"headers":{"X-Custom-Header":"application/json","Content-Type":"application/json"},"body":"{ \"message\": \"hello world\", \"location\": \"212.40.47.14\" }"}
DimaA6_ABC
  • 578
  • 4
  • 15
  • Tried the same from Linux machine and it worked. docker ps does not show anything sam-related running either, however until I added the user to docker group it would not start, so it definitely uses docker. Now where do I look on Windows? – DimaA6_ABC Nov 30 '21 at 14:04
  • Sam problem here on Windows an VSCode. Did you ever find a solution? – Christian Dechery Sep 29 '22 at 13:25

1 Answers1

1

This could be due to windows hostname resolution.

See my answer to a similar question https://stackoverflow.com/a/75484533/2353080

Michal
  • 2,078
  • 23
  • 36