1

I have a CDK solution with a stack etc and 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 libary, 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 and everything works.

But 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

2
  • if I understood correctly, your problem is to how to deploy lambda written in .net with cdk ? Commented Feb 17, 2023 at 6:21
  • Its an ASP.Net minimal API, with top level statements and I want to deploy using CDK. I emphasis the top level statement as I know this dictates what function-handler you put. If I deploy just using "dotnet lambda deploy-function" everything works. Commented Feb 17, 2023 at 8:48

1 Answer 1

0

Looking at your repo and the error message in the question...

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

Could it be the project is outputing a DLL called lambdaMinimalAPI but your code is specifying different casing (pascal casing API at the end)

var lambdaFunction = new Function(this, "lambdaMinimalAPI", new FunctionProps
{
    Runtime = Runtime.DOTNET_6,
    Code = Code.FromAsset("src/lambdaMinimalApi",assetOptions),
    Handler = "lambdaMinimalApi",
    Environment = new Dictionary<string, string>
    {
        ["userProfilesTable"] = userProfilesTable.TableName,
        ["tweetsTable"] = tweetsTable.TableName,
    },
    MemorySize = 256,
    Timeout = Duration.Seconds(30),
    Architecture = Architecture.X86_64
});

Hanlder should be like so:

Handler = "lambdaMinimalAPI", // UPPERCASE API
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.