aws-sam-cli: 'sam init --runtime dotnet' doesn't work with 'sam local start-api'
Description:
The auto-generated HelloWorld function for .Net sam init --runtime dotnet
doesn’t work when trying to run locally on Docker with the sam local start-api
command.
Steps to reproduce the issue:
sam init --runtime dotnet
cd sam-app
.\build.ps1
sam local start-api
curl http://localhost:3000/hello
Observed result: {“message”:“Internal server error”}
2018-09-20 22:32:43 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2018-09-20 22:32:43 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
2018-09-20 22:32:43 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2018-09-20 22:32:46 Invoking HelloWorld::HelloWorld.Function::FunctionHandler (dotnetcore2.0)
2018-09-20 22:32:46 Found credentials in shared credentials file: ~/.aws/credentials
Fetching lambci/lambda:dotnetcore2.0 Docker container image......
2018-09-20 22:32:50 Mounting G:\Code\AWS\SAM_test\sam-app\src\HelloWorld\bin\Debug\netcoreapp2.0\publish as /var/task:ro inside runtime container
Unhandled Exception: AWSLambda.Internal.Bootstrap.LambdaValidationException: Could not find the specified handler assembly with the file name 'HelloWorld, Culture=neutral, PublicKeyToken=null'. The assembly should be located in the root of your uploaded .zip file.
at AWSLambda.Internal.Bootstrap.UserCodeLoader.Init(Action`1 customerLoggingAction) in /opt/workspace/LambdaSandboxCoreCLR-2-0/src/Bootstrap/UserCodeLoader.cs:line 91
at MockLambdaRuntime.Program.Main(String[] args) in /source/Program.cs:line 28
2018-09-20 22:32:51 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:
2018-09-20 22:32:51 127.0.0.1 - - [20/Sep/2018 22:32:51] "GET /hello HTTP/1.1" 502 -
2018-09-20 22:32:51 127.0.0.1 - - [20/Sep/2018 22:32:51] "GET /favicon.ico HTTP/1.1" 403
Expected result: {“message”:“hello world”,“location”:" < IP Address > "}
2018-09-20 22:38:37 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2018-09-20 22:38:37 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
2018-09-20 22:38:37 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2018-09-20 22:38:42 Invoking HelloWorld::HelloWorld.Function::FunctionHandler (dotnetcore2.0)
2018-09-20 22:38:42 Found credentials in shared credentials file: ~/.aws/credentials
Fetching lambci/lambda:dotnetcore2.0 Docker container image......
2018-09-20 22:38:46 Mounting G:\Code\AWS\SAM_test\sam-app\publish\HelloWorld as /var/task:ro inside runtime container
START RequestId: d0fba56e-f336-4c14-b8a0-45404b131744 Version: $LATEST
END RequestId: d0fba56e-f336-4c14-b8a0-45404b131744
REPORT RequestId d0fba56e-f336-4c14-b8a0-45404b131744 Duration: 966 ms Billed Duration: 1000 ms Memory Size 128 MB
Max Memory Used: 46 MB
2018-09-20 22:38:48 127.0.0.1 - - [20/Sep/2018 22:38:48] "GET /hello HTTP/1.1" 200 -
Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Windows 10
Output of sam --version
:
SAM CLI, version 0.6.0
I was able to get the expected result by modifying the template.yaml file.
17: CodeUri: src/HelloWorld/bin/Debug/netcoreapp2.0/publish
becomes
17: CodeUri: publish/HelloWorld
It seems to be a mismatch between where the build.cake configuration puts files and where the template.yaml file is expecting them.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (7 by maintainers)
@the-xareth Just pushed that to a PR that’s pending merge and this should be fixed in the next release.
Changing to
CodeUri: ./artifacts/HelloWorld.zip
should fix it but could also use Publish too.