运行sam local时,invoke容器没有响应



我正试图在本地运行Amazon lambda,但我做不到。部署和运行AWS运行良好。我已经为IntelliJ IDEA安装了AWS插件,但这个想法似乎没有问题,因为我在独立的sam调用中也遇到了同样的错误。我在Windows上安装了docker,可以在命令行中运行docker ps

我正在运行:

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-sambuildHelloWorldFunction 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-sambuildHelloWorldFunction as /var/task:ro,delegated inside runtime container
No response from invoke container for HelloWorldFunction

调用start-api命令时,没有docker容器在运行(docker ps不返回任何内容(。

当在Linux上运行相同的程序时,我得到:

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" }"}

这可能是由于windows主机名解析。

查看我对类似问题的回答https://stackoverflow.com/a/75484533/2353080

最新更新