Search in sources :

Example 6 with LambdaClient

use of software.amazon.awssdk.services.lambda.LambdaClient in project aws-doc-sdk-examples by awsdocs.

the class CreateFunction method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <functionName> <filePath> <role> <handler> \n\n" + "Where:\n" + "    functionName - the name of the Lambda function. \n" + "    filePath - the path to the ZIP or JAR where the code is located. \n" + "    role - the role ARN that has Lambda permissions. \n" + "    handler - the fully qualifed method name (for example, example.Handler::handleRequest).  \n";
    if (args.length != 4) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String functionName = args[0];
    String filePath = args[1];
    String role = args[2];
    String handler = args[3];
    Region region = Region.US_WEST_2;
    LambdaClient awsLambda = LambdaClient.builder().region(region).build();
    createLambdaFunction(awsLambda, functionName, filePath, role, handler);
    awsLambda.close();
}
Also used : LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) Region(software.amazon.awssdk.regions.Region)

Example 7 with LambdaClient

use of software.amazon.awssdk.services.lambda.LambdaClient in project aws-doc-sdk-examples by awsdocs.

the class DeleteFunction method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <functionName> \n\n" + "Where:\n" + "    functionName - the name of the Lambda function \n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String functionName = args[0];
    Region region = Region.US_EAST_1;
    LambdaClient awsLambda = LambdaClient.builder().region(region).build();
    deleteLambdaFunction(awsLambda, functionName);
    awsLambda.close();
}
Also used : LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) Region(software.amazon.awssdk.regions.Region)

Example 8 with LambdaClient

use of software.amazon.awssdk.services.lambda.LambdaClient in project aws-doc-sdk-examples by awsdocs.

the class LambdaInvoke method main.

/*
   *  Function names appear as arn:aws:lambda:us-west-2:335556666777:function:HelloFunction
   *  you can retrieve the value by looking at the function in the AWS Console
   *
   * Also, ensure that you have setup your development environment, including your credentials.
   *
   * For information, see this documentation topic:
   *
   * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
   */
public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <functionName> \n\n" + "Where:\n" + "    functionName - the name of the Lambda function \n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String functionName = args[0];
    Region region = Region.US_EAST_1;
    LambdaClient awsLambda = LambdaClient.builder().region(region).build();
    invokeFunction(awsLambda, functionName);
    awsLambda.close();
}
Also used : LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) Region(software.amazon.awssdk.regions.Region)

Example 9 with LambdaClient

use of software.amazon.awssdk.services.lambda.LambdaClient in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method testLambdaInvokeSubsegmentContainsFunctionName.

@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() throws Exception {
    SdkHttpClient mockClient = mockSdkHttpClient(generateLambdaInvokeResponse(200));
    LambdaClient client = LambdaClient.builder().httpClient(mockClient).endpointOverride(URI.create("http://example.com")).region(Region.of("us-west-42")).credentialsProvider(StaticCredentialsProvider.create(AwsSessionCredentials.create("key", "secret", "session"))).overrideConfiguration(ClientOverrideConfiguration.builder().addExecutionInterceptor(new TracingInterceptor()).build()).build();
    Segment segment = AWSXRay.getCurrentSegment();
    client.invoke(InvokeRequest.builder().functionName("testFunctionName").build());
    Assert.assertEquals(1, segment.getSubsegments().size());
    Subsegment subsegment = segment.getSubsegments().get(0);
    Map<String, Object> awsStats = subsegment.getAws();
    @SuppressWarnings("unchecked") Map<String, Object> httpResponseStats = (Map<String, Object>) subsegment.getHttp().get("response");
    Assert.assertEquals("Invoke", awsStats.get("operation"));
    Assert.assertEquals("testFunctionName", awsStats.get("function_name"));
    Assert.assertEquals("1111-2222-3333-4444", awsStats.get("request_id"));
    Assert.assertEquals("extended", awsStats.get("id_2"));
    Assert.assertEquals("Failure", awsStats.get("function_error"));
    Assert.assertEquals("us-west-42", awsStats.get("region"));
    Assert.assertEquals(0, awsStats.get("retries"));
    Assert.assertEquals(2L, httpResponseStats.get("content_length"));
    Assert.assertEquals(200, httpResponseStats.get("status"));
    Assert.assertEquals(false, subsegment.isInProgress());
}
Also used : LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Subsegment(com.amazonaws.xray.entities.Subsegment) Map(java.util.Map) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Aggregations

LambdaClient (software.amazon.awssdk.services.lambda.LambdaClient)9 Region (software.amazon.awssdk.regions.Region)5 Segment (com.amazonaws.xray.entities.Segment)4 Subsegment (com.amazonaws.xray.entities.Subsegment)4 Map (java.util.Map)4 Test (org.junit.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)4 Cause (com.amazonaws.xray.entities.Cause)3