Error Deploying Asp.Net Minimal API (with Top level statements) to lambda using .NET CDK

1

I have a CDK solution with a stack etc, in the same solution i have created a ASP.NET minimal API Lambda project.

When I deploy using the CDK I'm getting the ERROR:

Internal Server Error

When I check the logs I can see the Error:

Error: executable assembly /var/task/lambdaMinimalApi.dll was not found..

I know what this error is, it is trying to find the Lambda function thinking its a library, but mine is an executable. I know this as when I deploy the lambda with:

** dotnet lambda deploy-function ** through trial an error i found out this:

.NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name.

Following this and just using the assembly name I can deploy using: ** dotnet lambda deploy-function ** and everything works.

When it comes to the CDK I get the internal server error mentioned above.

My public repo is here: https://github.com/RollsChris/cdk-twitter-clone-dotnet

I think it will be a good example to add to the official examples if I can get it to work?

I have tried various forms of Code.From**, and searched the internet far and wide. Most examples are using a lambda function written in javascript but the CDK is using .NET.

Thanks

  • I've alerted another SA with expertise in this area, so hopefully we'll have an answer for you in the near future.

1 Answer
0

In your CDK code your're using aws-s3-assets, which is a high level construct that abstracts packaging AWS Lambda functions. The default behavior of this construct is to zip all the content into a folder and upload it to an Amazon Simple Storage Service (Amazon S3) bucket. That works great for Lambda runtimes like Python or Node.js, which do not require code compilation, but for .NET, Java, or Go, which requires code compilation you need to implement BundlingOptions, here's a code sample that show how to implement it, you'll notice that all the 3 Lambda function are Minimal API, just like the one you're trying to build

To learn more about, please read the blog post: Build, package, and publish .NET C# Lambda functions with the AWS CDK

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions