pratik
pratik

Reputation: 49

I am facing an issue to execute AWS Lambda function

enter image description here

While deploying lambda in C# I am getting an error as - "errorType": "LambdaException", "errorMessage": "Could not find the specified handler assembly with the file name '/var/task/AWSLambda1.dll' or '/var/task/AWSLambda1.ni.dll'. The assembly should be located in the root of your uploaded .zip file.". as a beginner Could any one provide me the steps to execute lambda in C#?

Upvotes: 4

Views: 11811

Answers (5)

Akshay
Akshay

Reputation: 457

It is possible that your runtime settings are not set to execute your function. Perform the following steps to modify your setting:

  1. Navigate to your AWS Lambda function.
  2. Under your Lambda, scroll down and navigate to Code tab.
  3. Scroll down to Runtime settings:

enter image description here

Modify the name to your function handler: enter image description here

This worked with me.

Upvotes: 4

Viktor
Viktor

Reputation: 636

I suppose that you most likely created the lambda locally first and then tried to upload the code using dotnet cli or VS.

Try before deploying to go to your aws-lambda-tools-defaults.json file in the solution and change function-handler value to the value that corresponds to the real namespace of your application that processes the event -{namespace of your application}::{function name}, for example AWSLambda1::AWSLambda1.Function::FunctionHandler or just change it in your publish form if you are deploying using VS:

enter image description here

Upvotes: 2

Ikigai programmeh
Ikigai programmeh

Reputation: 408

Late to the party but let me put my solution here to save someone else's time. I also got this type of error and fixed the error by matching the AWS Lambda function handler name the same as the assembly name of the handler function in the code/zip file. AWS Lambda Handler can be found under the Runtime settings of the Code tab.

Upvotes: 3

Ash
Ash

Reputation: 6035

I faced this error when I renamed my project and tried to Publish to AWS.
You can fix this in your function upload screen by changing your 'Assembly Name' to match the name of your project / generated assembly.

Since, if you've chosen the save settings for future deployments option, these settings are saved to aws-lambda-tools-defaults.json, you can search for the missing file name ("AWSLambda1" in this case ) in your entire solution, see if it's present in the json file mentioned above and change it to match your assembly name.

Upvotes: 1

Coco
Coco

Reputation: 906

I am using the Serverless Framework to run Lambda functions. I could invoke the function but it didn't work when I tried invoking it through the API Gateway. After trying for a couple of days I solved it this way:

Handler.cs:

using System; 
using Amazon.Lambda.Core;
using Amazon.Lambda.Serialization.Json;
using Amazon.Lambda.APIGatewayEvents;

[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace AwsDotnetCsharp { 
    public class Handler { 
        public APIGatewayProxyResponse Hello(APIGatewayProxyRequest request) { 
            return new APIGatewayProxyResponse() {
                StatusCode = 200, 
                Body = "Go Serverless v1.0! Your function executed successfully!", 
            }; 
        }    
    } 
}

serverless.yml:

service: csharpExample

provider:
  name: aws
  runtime: dotnetcore1.0

package:
  artifact: bin/release/netcoreapp1.0/deploy-package.zip

functions:
  hello:
    handler: CsharpHandlers::AwsDotnetCsharp.Handler::Hello
    events:
        - http:
            path: hello
            method: GET
            cors: true

I'm not sure if this is what you were asking for, but since I spent a lot of time on this issue I'd like to share it for anyone who runs into the same problem as I did.

Upvotes: 0

Related Questions