Search in sources :

Example 1 with InvokeResponse

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);
    }
}
Also used : InvokeResponse(software.amazon.awssdk.services.lambda.model.InvokeResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) InvokeRequest(software.amazon.awssdk.services.lambda.model.InvokeRequest) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException)

Aggregations

SdkBytes (software.amazon.awssdk.core.SdkBytes)1 InvokeRequest (software.amazon.awssdk.services.lambda.model.InvokeRequest)1 InvokeResponse (software.amazon.awssdk.services.lambda.model.InvokeResponse)1 LambdaException (software.amazon.awssdk.services.lambda.model.LambdaException)1