Reputation: 307
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
Initialized a new AWS Lambda function using dotnet new lambda.EmptyFunction --name myFirstFunction --profile default --region us-east-1
cd
into myFirstFunction
Run dotnet publish ./src/myFirstFunction/myFirstFunction.csproj
Navigate into ./src/myFirstFunction/bin/Debug/net6.0/publish
Compress all of the files into a single file named Archive.zip
.
From AWS Console in the Browser
Navigate to the myFirstFunction
Lambda function.
Click "Upload from -> .zip file" in the "Code Source" section
Choose Archive.zip
Navigate to the "test" tab once successfully uploaded
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
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:
myFirstFunction
;<project_name>::<namespace>.<class>::<method_name>
);Upvotes: 17