Example usage for com.amazonaws.services.lambda AWSLambdaAsyncClientBuilder defaultClient

List of usage examples for com.amazonaws.services.lambda AWSLambdaAsyncClientBuilder defaultClient

Introduction

In this page you can find the example usage for com.amazonaws.services.lambda AWSLambdaAsyncClientBuilder defaultClient.

Prototype

public static AWSLambdaAsync defaultClient() 

Source Link

Usage

From source file:example.lambda.InvokeLambdaFunctionCallback.java

License:Apache License

public static void main(String[] args) {
    String function_name = "HelloFunction";
    String function_input = "{\"who\":\"AWS SDK for Java\"}";

    AWSLambdaAsync lambda = AWSLambdaAsyncClientBuilder.defaultClient();
    InvokeRequest req = new InvokeRequest().withFunctionName(function_name)
            .withPayload(ByteBuffer.wrap(function_input.getBytes()));

    Future<InvokeResult> future_res = lambda.invokeAsync(req, new AsyncLambdaHandler());

    System.out.print("Waiting for async callback");
    while (!future_res.isDone() && !future_res.isCancelled()) {
        // perform some other tasks...
        try {/*from w  w  w.ja  v  a 2 s.  co m*/
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            System.err.println("Thread.sleep() was interrupted!");
            System.exit(0);
        }
        System.out.print(".");
    }
}