Nelson Dias
Nelson Dias

Reputation: 121

Step Functions: How to call a specific handler of lambda function

I've a simple java code that performs some queries agains a DynamoDB database. In the lambda function I've tested each method (handler) individually with success.

public class EmployeeDataHandler {
    
    
    public String addSingleEmployeeData(Object input, Context context) {
        
        // logic inside
        
    }

    
    public String addBulkEmployeeData(List<Object> inputObjectList, Context context) {
        
        // logic inside

    }
    
    
    public List<EmployeeItems> getAllItemsByDate(EmployeeItems input, Context context) { 
       
        // logic inside
    
    }


    public List<EmployeeItems> getAllItemsByDateAndId(EmployeeItems input, Context context) { 

        // logic inside

    }
    
    public List<EmployeeItems> getAllItemsByDateRange(EmployeeItems input, Context context) { 

        // logic inside

    }

}

The next step is to call a given handler (for instance, addBulkEmployeeData) in a Task step function part of a state machine.

My question is how do I manage to do that?

According to the documentation, I can only reference the lambda function "ARN" throught the field Resource:

{
  "Comment": "Basic example of the Amazon States Language using an AWS Lambda function",
  "StartAt": "TestState",
  "States": {
    "TestState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-central-1:11111111111111:function:java-test-lambda",
      "End": true
    }
  }
}

Thus, anyone knows how can I call a specific handler (eg. addBulkEmployeeData)?

Tks in advance for your kindness and support.

Upvotes: 2

Views: 1051

Answers (1)

Mark B
Mark B

Reputation: 200436

You can't specify the handler when you call a Lambda function. When you deploy a Lambda function you have to specify which handler will be used for all invocations of that Lambda function at the time of deployment.

Your options are either to deploy the Lambda function multiple times, with a different handler configured for each deployment, or you could possibly have a single handler that examines the request and then calls the appropriate method based on the request type.

Upvotes: 3

Related Questions