0

I need to call my lambda - A from lambda - B. I have done the required code but need few clarifications.

AWSLambda lambdaClient = AWSLambdaClientBuilder.standard().withRegion(region)
.withCredentials(new DefaultAWSCredentialsProviderChain()).build();

InvokeRequest request = new InvokeRequest().withClientContext(clientContext).withFunctionName(functionName)
          .withQualifier(alias).withPayload(payload).withInvocationType(InvocationType.Event);

InvokeResult response = lambdaClient.invoke(request);

I have a N number of table names which I need to pass from lambda B to lambda A one by one so that it can do the needful work on that DDB table.

The problem is withPayload takes a JSON payload which is passed to the lambda function.

I will pass the payload to lambda-B but then the code is calling lambdaClient.invoke(request) which will have all the table names and it will call our lambda-A. But handler function in the lambda-A expects a single table name.

I am not sure how to do this.

Also do i need to run this in a loop so that every time it takes new payload value and then calls lambdaClient.invoke(request) or does it happen automatically?

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

-1

You should create pyload with a single table name. In this case, you will have many payloads so you can have array of them and process them in a loop.

For Example:

InvokeRequest request = null;
InvokeResult response = null;
for(String payload : payloads){
  request = new InvokeRequest().withClientContext(clientContext).withFunctionName(functionName)
          .withQualifier(alias).withPayload(payload).withInvocationType(InvocationType.Event);
  response = lambdaClient.invoke(request);
}

In which case you will get that payload? Lamda normally runs on some event and a lambda cannot run more than 15 minutes(For more than 15 minutes you have to contact the AWS Support Team).

Shivang Agarwal
  • 1,825
  • 1
  • 14
  • 19