.Net Core (2.1)- Lambda function does work while i

2019-08-03 05:58发布

问题:

I've created a simple empty AWS Lambda function using .Net Core 2.1 :

Here is the folder structure :

(here is the csproj)

And a FunctionHandler which gets DI and invoke some dummy method :

Now let's run the "Mock Lambda Test Tool" , we can see that it works :

So where is the problem?

I've read here that 2.2 is supported :

This means you can now author Lambda functions using .NET Core 2.2 and .NET Core 3.0 preview. Amazon.Lambda.RuntimeSupport is available as source code on GitHub, or as a NuGet package.

And so , I've created a new empty lambda project but with 2.2 :

  • Here are the changes in the CSPROJ file
  • And here are the changes in the aws-lambda-tools-defaults.json file

Same code. But now when I run "Mock Lambda Test Tool" , I get an error :

AWS .NET Mock Lambda Test Tool (0.9.2) Unknown error occurred causing process exit: Failed to find a deps.json file at Amazon.Lambda.TestTool.Runtime.LocalLambdaRuntime.Initialize(String directory) in E:\JenkinsWorkspaces\Lam\LambdaSandboxCoreCLRApi\Tools\LambdaTestTool\Amazon.Lambda.TestTool\Runtime\LocalLambdaRuntime.cs:line 50 at Amazon.Lambda.TestTool.Program.Main(String[] args) in E:\JenkinsWorkspaces\Lam\LambdaSandboxCoreCLRApi\Tools\LambdaTestTool\Amazon.Lambda.TestTool\Program.cs:line 46 Press any key to exit

Here is the error :

Question:

Why is that? I didn't have any deps.json file in 2.1 .

So why do I need it in 2.2 ? Also, what is this path appearing in the error: E:\JenkinsWorkspaces... ? I don't have Jenkins nor something like it.

回答1:

Well, I've found out the reason for this (I don't know why it happened at first place) but here it is. Bear with me.

When I've created a 2.1 lambda project, everything was OK. ( obviously)

The problem was with 2.2 projects ( targeting 2.2 & nugets of 2.2). (which shows the error as I show in my question)

So then I thought, what if I'll create a 2.1 project and then update(!) its nugets and change target to 2.2 ? .........it worked!

This was really weird. Because I expected it not to.

So then I thought, let's compare file system for a 2.2 project (which doesn't work), with a 2.1 project that was updated to a 2.2 project (which does work, surprisingly).

On the right side, it's the strict 2.2 projects (no update), on the left it's the project that was UPDATED to 2.2 :

I've noticed some .Net core 2.1 files that were in the upgrade but weren't in the strict 2.2 version, so I thought, how can I get those missing files ?

So I've changed (temporarily) the project target to 2.1 :

Then I've run build

This caused the files for the 2.1 folders to appear :

And now ............. , all OK !!! :