use of com.amazonaws.services.lambda.AWSLambda 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.AWSLambda in project aws-xray-sdk-java by aws.
the class TracingHandlerTest method testLambdaInvokeSubsegmentContainsFunctionName.
@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() {
// Setup test
AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();
// Lambda returns "null" on successful fn. with no return value
mockHttpClient(lambda, "null");
// Test logic
Segment segment = AWSXRay.beginSegment("test");
InvokeRequest request = new InvokeRequest();
request.setFunctionName("testFunctionName");
InvokeResult r = lambda.invoke(request);
System.out.println(r.getStatusCode());
System.out.println(r);
Assert.assertEquals(1, segment.getSubsegments().size());
Assert.assertEquals("Invoke", segment.getSubsegments().get(0).getAws().get("operation"));
System.out.println(segment.getSubsegments().get(0).getAws());
Assert.assertEquals("testFunctionName", segment.getSubsegments().get(0).getAws().get("function_name"));
}
use of com.amazonaws.services.lambda.AWSLambda 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