use of software.amazon.awssdk.services.lambda.model.InvokeResponse in project aws-doc-sdk-examples by awsdocs.
the class LambdaInvoke method invokeFunction.
// snippet-start:[lambda.java2.invoke.main]
public static void invokeFunction(LambdaClient awsLambda, String functionName) {
InvokeResponse res = null;
try {
// Need a SdkBytes instance for the payload
String json = "{\"Hello \":\"Paris\"}";
SdkBytes payload = SdkBytes.fromUtf8String(json);
// Setup an InvokeRequest
InvokeRequest request = InvokeRequest.builder().functionName(functionName).payload(payload).build();
res = awsLambda.invoke(request);
String value = res.payload().asUtf8String();
System.out.println(value);
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations