'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 dotnetcd sam-app.\build.ps1sam local start-apicurl 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.
Thanks for raising this - Looks like this was introduced when Cake was added but I can double check that next week and include a fix on an existing PR that adds dotnet core 2.1 support — https://github.com/awslabs/aws-sam-cli/pull/665
Will circle back on this next Thursday or Friday On Thu, 20 Sep 2018 at 15:04, the-xareth [email protected] wrote:
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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/awslabs/aws-sam-cli/issues/673, or mute the thread https://github.com/notifications/unsubscribe-auth/ADL4BCUlbXdYHCeYg9-Cdh-c0TMLauhRks5uc5JngaJpZM4WyFbc .
@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.
When I auto generate using sam init --runtime dotnetcore2.0.. I'm also getting this error.
$ cd sam-app
$ sam local invoke HelloWorldFunction
2018-10-01 10:30:55 Reading invoke payload from stdin (you can also pass it from file with --event)
2018-10-01 10:30:57 Invoking HelloWorld::HelloWorld.Function::FunctionHandler (dotnetcore2.0)
2018-10-01 10:30:57 Starting new HTTP connection (1): 169.254.169.254
Fetching lambci/lambda:dotnetcore2.0 Docker container image......
2018-10-01 10:31:00 Mounting /root/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
Changing the CodeUri to publish/HelloWorld or ./artifacts/HelloWorld.zip still gives the same error.
I'm using Sam CLI, version 0.6.0 on Ubuntu 16.04 on Windows Subsystem for Linux (WSL)
Hey @ishu3101, out of curiosity, did you run the cake build script? Also, sam local invoke HelloWorldFunction expects an event to be passed[1].
Although I'm on OSX here's what I just did using the same SAM CLI version:
sam init -r dotnetcore2.0
cd sam-app/
# Open template.yaml and Change CodeUri to ./artifacts/HelloWorld.zip
sh build.sh --target=Package # Ggenerate artifacts folder and Zip file in the expected format
sam local start-api # Run a local API Gateway
# Open browser on http://localhost:3000/hello to test
[1] If you want to use sam local invoke over sam local start-api you can do any of the options below:
A) Generate a dummy API Gateway Proxy Event and Invoke with that
sam local generate-event apigateway aws-proxy > event.json
sam local invoke HelloWorldFunction -e event.json
B) Pipe an event to sam local invoke via Stdin
sam local generate-event apigateway aws-proxy | sam local invoke HelloWorldFunction
@heitorlessa. No I did not run the cake build script before. With CodeUri set to ./artifacts/HelloWorld.zip
$ sh build.sh --target=Package
build.sh: 10: build.sh: Bad substitution
build.sh: 23: build.sh: [[: not found
build.sh: 31: build.sh: Syntax error: "(" unexpected
$ bash build.sh --target=Package
Downloading packages.config...
Downloading NuGet...
build.sh: line 74: mono: command not found
Could not restore NuGet tools.
@ishu3101 okay, great. That explains it. However, you're on Windows and the command for Windows is in the README.md
build.ps1 --target=Package
Mono is only required for Linux/OSX hence two different scripts (non-Windows, Windows). Give that a try and let me know if that solves it.
I'm using Windows Subsystem for Linux with Ubuntu
Slightly related to this issue but I ran into something similar (with both sam local and with my deployed stack of course).
sam init --name foobar --runtime nodejs8.10
sam local start-api # errors out
The issue was that the hello_world/lambdaHandler.js did not conform to Output Format of a Lambda Function for Proxy Integration. My co-worker @rubene was quick to point this out and after updating the to match the Output Format I was good to go.
Do you know if there's an already open issue for this? If not I can open one.
@ishu3101 If you're going to use DotNet CLI and develop DotNet on Subsystem for Linux then you need Mono, otherwise you don't need that and can run build.ps1 on any powershell.
cc @sliedig, please correct me if I'm wrong as I never tried developing DotNet on Windows Subsystem.
@jbabe Have you installed the dependencies after you did sam init --name foobar --runtime nodejs8.10 as specified in the README.md?
If yes and you still encountered that issue please open up a new issue for that. I've just tried the following and can't reproduce the issue:
sam init --name foobar --runtime nodejs8.10
cd hello_world && npm install && cd ..
sam local start-api
PS: There is no hello_world/lambdaHandler.js but hello_world/app.js in the init sample.
@heitorlessa After installing mono and running bash build.sh --target=Package, I'm getting this error.
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
File name: 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at System.Lazy`1[T].CreateValue () [0x00075] in <8f2c484307284b51944a1a13a14c0266>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
File name: 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at System.Lazy`1[T].CreateValue () [0x00075] in <8f2c484307284b51944a1a13a14c0266>:0
Could not restore NuGet tools.
@ishu3101 If you're going to use DotNet CLI and develop DotNet on Subsystem for Linux then you need Mono, otherwise you don't need that and can run build.ps1 on any powershell.
cc @sliedig, please correct me if I'm wrong as I never tried developing DotNet on Windows Subsystem.
@heitorlessa The PowerShell script works on Windows, but haven't got it to run on on mac or linux yet. It don't think its a compatibility issue, maybe just a script bug. Need to investigate this further and maybe raise a separate bug/pr for this.
@ishu3101 If you're going to use DotNet CLI and develop DotNet on Subsystem for Linux then you need Mono, otherwise you don't need that and can run build.ps1 on any powershell.
cc @sliedig, please correct me if I'm wrong as I never tried developing DotNet on Windows Subsystem.
@jbabe Have you installed the dependencies after you did
sam init --name foobar --runtime nodejs8.10as specified in the README.md?If yes and you still encountered that issue please open up a new issue for that. I've just tried the following and can't reproduce the issue:
sam init --name foobar --runtime nodejs8.10 cd hello_world && npm install && cd .. sam local start-apiPS: There is no
hello_world/lambdaHandler.jsbuthello_world/app.jsin the init sample.
Hi @heitorlessa, thanks for the quick response!
I did install the dependencies...when I get a chance I'll create a repo and try to recreate. I'll open a new issue if I can recreate.
Good catch on hello_world/lambdaHandler.js vs hello_world/app.js`.
Closing. Was released with 0.6.1
Hi Gues I desperately need help I using SAM CLI, version 0.6.1 and trying to run the hello world sample on Windows 10 using a Linux Container.
I am getting the following error:
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.
I have tried everything mentioned on https://github.com/awslabs/aws-sam-cli/issues/673 (edited)
I am not sure if you can use windows containers instead of linux
I'm observing the same behaviour with SAM version 6.0.2. HelloWorld artifact produced using build.ps1 uploaded to AWS with same handler name is being executed correctly while local invocation yields:
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
In debug I can observed that Assebmly is actuall present
2018-11-16 10:45:29 Decompressing C:\dev\aws\customer-app\sam-tests\sam-app\artifacts\HelloWorld.zip
2018-11-16 10:45:29 File Amazon.Lambda.APIGatewayEvents.dll in zipfile does not have permission information
2018-11-16 10:45:29 File Amazon.Lambda.Core.dll in zipfile does not have permission information
2018-11-16 10:45:29 File Amazon.Lambda.Serialization.Json.dll in zipfile does not have permission information
2018-11-16 10:45:29 File HelloWorld.deps.json in zipfile does not have permission information
2018-11-16 10:45:29 File HelloWorld.dll in zipfile does not have permission information
2018-11-16 10:45:29 File HelloWorld.pdb in zipfile does not have permission information
2018-11-16 10:45:29 File HelloWorld.runtimeconfig.json in zipfile does not have permission information
2018-11-16 10:45:29 File Newtonsoft.Json.dll in zipfile does not have permission information
My issue was caused by firewall blocking Docker drive
I've faced the same issue. Fixed using recommendation from https://stackoverflow.com/a/43527876. Very unclear issue.