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
Use this LATEST code to invoke a Lambda Function Synchronously:
final String AWS_ACCESS_KEY_ID = "xx";
final String AWS_SECRET_ACCESS_KEY = "xx";
AWSCredentials credentials = new BasicAWSCredentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
// ARN
String functionName = "XXXX";
//This will convert object to JSON String
String inputJSON = new Gson().toJson(userActivity);
InvokeRequest lmbRequest = new InvokeRequest()
.withFunctionName(functionName)
.withPayload(inputJSON);
lmbRequest.setInvocationType(InvocationType.RequestResponse);
AWSLambda lambda = AWSLambdaClientBuilder.standard()
.withRegion(Regions.US_EAST_1)
.withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
InvokeResult lmbResult = lambda.invoke(lmbRequest);
String resultJSON = new String(lmbResult.getPayload().array(), Charset.forName("UTF-8"));
System.out.println(resultJSON);
Use these dependencies to avoid any errors:
org.codehaus.janino
janino
2.6.1
//Required by BeanstalkDeploy.groovy at runtime
org.apache.httpcomponents
httpclient
4.5.2
runtime
com.amazonaws
aws-java-sdk-lambda
1.11.207