use of com.amazonaws.services.lambda.model.ServiceException in project aws-doc-sdk-examples by awsdocs.
the class LambdaInvokeFunction method main.
public static void main(String[] args) {
/*
Function names appear as arn:aws:lambda:us-west-2:335556330391:function:HelloFunction
you can retrieve the value by looking at the function in the AWS Console
*/
if (args.length < 1) {
System.out.println("Please specify a function name");
System.exit(1);
}
// snippet-start:[lambda.java1.invoke.main]
String functionName = args[0];
InvokeRequest invokeRequest = new InvokeRequest().withFunctionName(functionName).withPayload("{\n" + " \"Hello \": \"Paris\",\n" + " \"countryCode\": \"FR\"\n" + "}");
InvokeResult invokeResult = null;
try {
AWSLambda awsLambda = AWSLambdaClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(Regions.US_WEST_2).build();
invokeResult = awsLambda.invoke(invokeRequest);
String ans = new String(invokeResult.getPayload().array(), StandardCharsets.UTF_8);
// write out the return value
System.out.println(ans);
} catch (ServiceException e) {
System.out.println(e);
}
System.out.println(invokeResult.getStatusCode());
// snippet-end:[lambda.java1.invoke.main]
}
use of com.amazonaws.services.lambda.model.ServiceException in project aws-doc-sdk-examples by awsdocs.
the class ListFunctions method main.
public static void main(String[] args) {
// snippet-start:[lambda.java1.list.main]
ListFunctionsResult functionResult = null;
try {
AWSLambda awsLambda = AWSLambdaClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(Regions.US_WEST_2).build();
functionResult = awsLambda.listFunctions();
List<FunctionConfiguration> list = functionResult.getFunctions();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
FunctionConfiguration config = (FunctionConfiguration) iter.next();
System.out.println("The function name is " + config.getFunctionName());
}
} catch (ServiceException e) {
System.out.println(e);
}
// snippet-end:[lambda.java1.list.main]
}
Aggregations