Developer
Developer

Reputation: 307

C# AWS Lambda Function - Could not find the specified handler assembly with the file name 'LambdaTest, Culture=neutral, PublicKeyToken=null'

I am trying to create a "Hello, World" AWS Lambda function, with one minor change: I need to deploy it using a .zip file. In an effort to accomplish this, I've done the following:

From the Terminal Window

  1. Initialized a new AWS Lambda function using dotnet new lambda.EmptyFunction --name myFirstFunction --profile default --region us-east-1

  2. cd into myFirstFunction

  3. Run dotnet publish ./src/myFirstFunction/myFirstFunction.csproj

  4. Navigate into ./src/myFirstFunction/bin/Debug/net6.0/publish

  5. Compress all of the files into a single file named Archive.zip.

From AWS Console in the Browser

  1. Navigate to the myFirstFunction Lambda function.

  2. Click "Upload from -> .zip file" in the "Code Source" section

  3. Choose Archive.zip

  4. Navigate to the "test" tab once successfully uploaded

  5. Click the "Test" button in the "Test event" section

At this point, I receive an error that says:

{
  "errorType": "LambdaValidationException",
  "errorMessage": "Could not find the specified handler assembly with the file name 'LambdaTest, Culture=neutral, PublicKeyToken=null'. The assembly should be located in the root of your uploaded .zip file.",
  "stackTrace": [
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Init(Action`1 customerLoggingAction) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 95",
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeInitializer.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeInitializer.cs:line 46",
    "at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 155"
  ]
}

I'm unsure how to fix this. I do not see "LambdaTest" in any of the config files. So, I have no idea where that identifier is coming from. What do I need to do to get this based Lambda function working via the "test" tab in the AWS Console?

Upvotes: 7

Views: 11750

Answers (1)

Fábio
Fábio

Reputation: 575

What happens is that AWS is not able to indentify where your function handler is.

When you create a Lambda in AWS, by default it assigns a LambdaTest handler.

During the deployment of your Lambda code, you need to ensure you are deploying a correct handler for your function.

I could be more helpful if I knew your code and the solution structure, but lets give a try.

Under /src/myFirstFunction you might have a file called aws-lambda-tools-defaults.json. In that file, there will be a key "function-handler" and the value should point to your function handler, in the format: <project_name>::<namespace>.<class>::<method_name>

Imagine you have:

namespace Farm
{
    public class Banana
    {
        public string Harvest(string season, ILambdaContext context)
        {
            ...
        }
    } 
}

Your handler should be myFirstFunction::Farm.Banana::Harvest

More info on: https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/lambda-creating-project-in-visual-studio.html


If you not using Visual Studio:

  • Access AWS Management Console;
  • Navigate to your Lambda function myFirstFunction;
  • Under the Code tab, you will see the Runtime settings. Press Edit;
  • Change the handler name according to the format I mentioned above (<project_name>::<namespace>.<class>::<method_name>);
  • Save and test

Upvotes: 17

Related Questions