How to invoke the AWS lambda function / handler from Java code

前端 未结 5 1551
耶瑟儿~
耶瑟儿~ 2021-01-19 18:40

I am new to AWS lambda I have created a lambda function with handler

example.Orders::orderHandler

And this is the custom handler, now I wa

5条回答
  •  不知归路
    2021-01-19 19:11

    I followed the following code and just printed the response from the Lambda

    AWSLambdaAsyncClient lambdaClient = new AWSLambdaAsyncClient();
        lambdaClient.withRegion(Region.getRegion(Regions.US_WEST_2));
        InvokeRequest invokeRequest = new InvokeRequest();
        invokeRequest.setInvocationType("RequestResponse"); // ENUM RequestResponse or Event
        invokeRequest.withFunctionName("FUNCTION NAME").withPayload(payload);
        InvokeResult invoke = lambdaClient.invoke(invokeRequest);
        try {
            // PRINT THE RESPONSE
            String val = new String(invoke.getPayload().array(), "UTF-8");
            System.out.println("Response==> " + val);
        } catch (Exception e) {
            System.out.println("error");
        }
    

提交回复
热议问题