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

Error while running AWS Lambda .NET Core Deployment Task #80

Closed
kevbite opened this Issue May 21, 2018 · 16 comments

Comments

Projects
None yet
3 participants
@kevbite

kevbite commented May 21, 2018

We seem to be getting the following error when running the deployment task:

2018-05-21T15:59:48.3073486Z Task         : AWS Lambda .NET Core Deployment
2018-05-21T15:59:48.3073691Z Description  : Build and deploy a Serverless .NET Core application or AWS Lambda function
2018-05-21T15:59:48.3073879Z Version      : 1.0.21
2018-05-21T15:59:48.3074024Z Author       : Amazon Web Services
2018-05-21T15:59:48.3074243Z Help         : Please refer to [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/) for more information on working with AWS Lambda.
2018-05-21T15:59:48.3074497Z ==============================================================================
2018-05-21T15:59:48.6353879Z 77ba38e3-79ed-42df-9b9b-2c74eb4ae652 exists true
2018-05-21T15:59:48.6398122Z Deploying Lambda project at D:\a\r1\a\_ProjectX.Audit Build\drop
2018-05-21T15:59:48.6416695Z Beginning dotnet restore
2018-05-21T15:59:48.6446617Z Path to tool: C:\Program Files\dotnet\dotnet.exe
2018-05-21T15:59:48.6478248Z [command]"C:\Program Files\dotnet\dotnet.exe" restore
2018-05-21T15:59:48.8334085Z MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
2018-05-21T15:59:48.8526334Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2018-05-21T15:59:48.8569458Z ##[section]Finishing: Deploy to Lambda:  Development

I don't really get why it's trying to run dotnet restore?

We've set up a build pipeline to just pack up our .net core serverless application and then we've got another release pipeline to pick up the artifacts and deployment them to aws via this task.

image

What I find weird is if I run it locally using dotnet lambda deploy-serverless using the following aguments it works totally fine:
dotnet lambda deploy-serverless --package .\bin\Release\netcoreapp2.0\xxx.zip --template-parameters "xxx=aaa;yyy=bbb"

@kevbite

This comment has been minimized.

kevbite commented May 21, 2018

Ah OK I see what is going off now, the first step to this task is to run dotnet restore to pull in the cli tools package. As a workaround I've just hacked in a step before running this task to create a temp.csproj so that it can use the dotnet cli tools.

Set-Content -Path ".\temp.csproj" -Value '<Project Sdk="Microsoft.NET.Sdk">
>>
>>   <PropertyGroup>
>>     <TargetFramework>netcoreapp2.0</TargetFramework>
>>   </PropertyGroup>
>>
>>   <ItemGroup>
>>     <DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.1.3" />
>>   </ItemGroup>
>>
>> </Project>
>> '
@steveataws

This comment has been minimized.

Contributor

steveataws commented Jun 13, 2018

Wouldn't it be simpler to add the tools reference to the your actual project, so you have access to the dotnet cli extensions for Lambda where ever you are using this project?

@kevbite

This comment has been minimized.

kevbite commented Jun 13, 2018

We package our lambda application up using the following CLI command within our build agent:

dotnet lambda package --output-package ./package.zip

then we list them as artifacts to a build
then we release them using a completely separate pipeline within the release manager, this allows us to track release and also publish to multiple stacks.

@steveataws

This comment has been minimized.

Contributor

steveataws commented Jun 14, 2018

OK, that's what I'd expect. Is there anything needed from us on this issue or can we close it?

@kevbite

This comment has been minimized.

kevbite commented Jun 14, 2018

No totally fine, just took a bit of working out how the plugin worked.

The workaround works perfectly fine for just pulling in the CLI tool.

Thanks

@steveataws

This comment has been minimized.

Contributor

steveataws commented Jun 29, 2018

Don't think there is any work to do here, so resolving. Feel free to reopen if needed.

@steveataws steveataws closed this Jun 29, 2018

@angelo250

This comment has been minimized.

angelo250 commented Jul 14, 2018

@kevbite We are using a similar CI pipeline setup (Build: build/publish w .NET core, Release: deploy using AWS deployment task) and ran into the same issue you described about project file missing. I used your workaround to create a temp .csProj file and the error about missing csProj file goes away. But now I'm getting what appears to be a compile error from the lambda deploy-function.

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point. 

Any help will be appreciated to point me in the right direction to get CI working.

Logs:

2018-07-14T14:01:38.5099411Z ##[section]Starting: Deploy to Lambda
2018-07-14T14:01:38.5099411Z ==============================================================================
2018-07-14T14:01:38.5099411Z Task         : AWS Lambda .NET Core Deployment
2018-07-14T14:01:38.5099411Z Description  : Build and deploy a Serverless .NET Core application or AWS Lambda function
2018-07-14T14:01:38.5099411Z Version      : 1.0.21
2018-07-14T14:01:38.5099411Z Author       : Amazon Web Services
2018-07-14T14:01:38.5099411Z Help         : Please refer to [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/) for more information on working with AWS Lambda.
2018-07-14T14:01:38.5099411Z ==============================================================================
2018-07-14T14:01:38.9318221Z 695978a9-f4fb-4942-8816-812448a9bfe1 exists true
2018-07-14T14:01:38.9474469Z Deploying Lambda project at C:\agent\_work\r3\a\API\drop
2018-07-14T14:01:38.9630735Z Beginning dotnet restore
2018-07-14T14:01:38.9786977Z Path to tool: C:\Program Files\dotnet\dotnet.exe
2018-07-14T14:01:38.9786977Z [command]"C:\Program Files\dotnet\dotnet.exe" restore
2018-07-14T14:01:40.6817902Z   Restoring packages for C:\agent\_work\r3\a\API\drop\API.csproj...
2018-07-14T14:01:43.9317501Z   Generating MSBuild file C:\agent\_work\r3\a\API\drop\obj\API.csproj.nuget.g.props.
2018-07-14T14:01:43.9473919Z   Generating MSBuild file C:\agent\_work\r3\a\API\drop\obj\API.csproj.nuget.g.targets.
2018-07-14T14:01:44.0098768Z   Restore completed in 3.3 sec for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:44.0255010Z   Restore completed in 17.17 ms for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:44.0567512Z   Restore completed in 28.76 ms for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:44.1348771Z Beginning Lambda Deployment
2018-07-14T14:01:44.1348771Z Path to tool: C:\Program Files\dotnet\dotnet.exe
2018-07-14T14:01:44.1348771Z [command]"C:\Program Files\dotnet\dotnet.exe" lambda deploy-function --disable-interactive true --region us-west-2 -fn MyFunction -fh MyApp::MyClass::MyMethod --function-role xxxxx --function-memory-size 512 --function-timeout 300 --configuration Release --framework netcoreapp2.0 --function-runtime dotnetcore2.0
2018-07-14T14:01:45.0723849Z Amazon Lambda Tools for .NET Core applications (2.2.0)
2018-07-14T14:01:45.0723849Z Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet
2018-07-14T14:01:45.0723849Z 	
2018-07-14T14:01:45.2910865Z Executing publish command
2018-07-14T14:01:45.3067118Z ... invoking 'dotnet publish', working folder 'C:\agent\_work\r3\a\API\drop\bin\Release\netcoreapp2.0\publish'
2018-07-14T14:01:45.8379674Z ... publish: Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
2018-07-14T14:01:45.8379674Z ... publish: Copyright (C) Microsoft Corporation. All rights reserved.
2018-07-14T14:01:46.7598290Z ... publish:   Restoring packages for C:\agent\_work\r3\a\API\drop\API.csproj...
2018-07-14T14:01:48.5879231Z ... publish:   Restore completed in 1.79 sec for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:48.6504244Z ... publish:   Restore completed in 20.8 ms for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:48.6504244Z ... publish:   Restore completed in 16.73 ms for C:\agent\_work\r3\a\API\drop\API.csproj.
2018-07-14T14:01:52.0566348Z ... publish: CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:\agent\_work\r3\a\API\drop\API.csproj]
2018-07-14T14:01:52.1191355Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 4294967295
2018-07-14T14:01:52.1347617Z ##[section]Finishing: Deploy to Lambda
@kevbite

This comment has been minimized.

kevbite commented Jul 14, 2018

Hey @angelo250, are you deploying a serverless application or just the lambda function? All I did was replicate what I was doing locally deploying it with the dotnet CLI. Here's a screenshot of our release task for deploying a serverless application, hope it's useful:

image

@angelo250

This comment has been minimized.

angelo250 commented Jul 14, 2018

@kevbite it’s a stand-alone lambda function. I will try to deploy locally with the CLI and see what I get. I’ll report back on Monday.

@kevbite

This comment has been minimized.

kevbite commented Jul 15, 2018

@angelo250 looking at your logs it seems you're missing the --package argument to pass into the dotnet lambda CLI command, this will stop it trying to do a build and deploy, and just deploy the specified package instead.

@angelo250

This comment has been minimized.

angelo250 commented Jul 16, 2018

@kevbite that did it! Thank you! I had searched through the source of deploy-function and found the package parameter but didn't find how to pass it to the lambda publish method. Is there an online reference?

@kevbite

This comment has been minimized.

kevbite commented Jul 17, 2018

Glad you got it sorted @angelo250. Nope, I couldn't find any online sources, I just found it from digging around and seeing how things work 👍

@steveataws

This comment has been minimized.

Contributor

steveataws commented Jul 17, 2018

Just to let you know, we have some changes coming that we believe significantly enhances these tasks to make packaging and subsequent deployment, from separate build or release pipelines, of Lambda functions and Serverless applications much easier.

I don't have a specific ETA I can share but I'm talking a matter of weeks, not months, before release. Hopefully this will make your lives a lot simpler :-)

@kevbite

This comment has been minimized.

kevbite commented Jul 17, 2018

@steveataws that would be great, thanks for the information!

@angelo250

This comment has been minimized.

angelo250 commented Jul 21, 2018

@steveataws thank you! Looking forward to the release.

@kevbite

This comment has been minimized.

kevbite commented Aug 19, 2018

I've now blogged a step by step guide on how to get around this - https://kevsoft.net/2018/08/13/build-and-releasing-with-vsts-for-multiple-aws-serverless-stacks.html

Might be useful for other people until we get the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment