From ff92580e719b4b2a077aaf2d5135c1fb9d296e6e Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 1 Sep 2021 02:06:58 +0100 Subject: [PATCH] Successfully map s3Event --- test-lambda/build.gradle | 9 +++-- .../java/com/example/TestRequestHandler.java | 34 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/test-lambda/build.gradle b/test-lambda/build.gradle index a5cf0fc..2d1b9cf 100644 --- a/test-lambda/build.gradle +++ b/test-lambda/build.gradle @@ -21,13 +21,18 @@ micronaut { dependencies { implementation("io.micronaut:micronaut-runtime") - implementation("io.micronaut.xml:micronaut-jackson-xml") implementation("javax.annotation:javax.annotation-api") - runtimeOnly("ch.qos.logback:logback-classic") + implementation platform('com.amazonaws:aws-java-sdk-bom:1.12.58') + implementation('com.amazonaws:aws-java-sdk-s3') + implementation("io.micronaut.aws:micronaut-aws-sdk-v2:3.0.0") { + force = true + } implementation("io.micronaut.aws:micronaut-function-aws") + implementation('com.fasterxml.jackson.core:jackson-databind:2.12.5') implementation("com.amazonaws:aws-lambda-java-core:1.2.1") implementation("com.amazonaws:aws-lambda-java-events:3.9.0") + runtimeOnly("ch.qos.logback:logback-classic") } diff --git a/test-lambda/src/main/java/com/example/TestRequestHandler.java b/test-lambda/src/main/java/com/example/TestRequestHandler.java index ddbaf35..ebbcce5 100644 --- a/test-lambda/src/main/java/com/example/TestRequestHandler.java +++ b/test-lambda/src/main/java/com/example/TestRequestHandler.java @@ -1,28 +1,50 @@ package com.example; -import com.amazonaws.services.lambda.runtime.events.S3Event; import com.amazonaws.services.lambda.runtime.events.SNSEvent; +import com.amazonaws.services.s3.event.S3EventNotification; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.micronaut.function.aws.MicronautRequestHandler; import jakarta.inject.Inject; -public class TestRequestHandler extends MicronautRequestHandler { +public class TestRequestHandler extends MicronautRequestHandler { @Inject ObjectMapper objectMapper; @Override - public Void execute(SNSEvent.SNS input) { + public Void execute(SNSEvent input) { + System.out.println("##################################### Invocation Start #################################################"); + System.out.println("This is the SNSEvent: " + input.toString()); try { - S3Event s3Event = objectMapper.readValue(input.getMessage(), S3Event.class); - String message = s3Event.toString(); - System.out.println(message); + S3EventNotification s3EventNotification = objectMapper.readValue(input.getRecords().get(0).getSNS().getMessage(), S3EventNotification.class); + String message = s3EventNotification.toString(); + System.out.println("This is the s3EventNotification with ObjectMapper: " + message); + System.out.println("This is the s3EventNotificationRecord: " + s3EventNotification.getRecords().get(0).toString()); + System.out.println("This is the s3EventNotificationRecord Arn: " + s3EventNotification.getRecords().get(0).getS3().getBucket().getArn()); + System.out.println("This is the s3EventNotificationRecord Key: " + s3EventNotification.getRecords().get(0).getS3().getObject().getKey()); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } +// try { +// Map map = objectMapper.readValue(input.getRecords().get(0).getSNS().getMessage(), new TypeReference>() {}); +// String message = map.toString(); +// System.out.println("This is an S3Event Map" + message); +// } catch (JsonProcessingException jpe) { +// jpe.printStackTrace(); +// } +//// +// +// try { +// S3EventNotification.S3EventNotificationRecord s3EventNotificationRecord = objectMapper.readValue(input.getRecords().get(0).getSNS().get., S3EventNotification.S3EventNotificationRecord.class); +// String message = s3EventNotificationRecord.toString(); +// System.out.println("This is the s3EventRecordNotification: " + message); +// } catch (JsonProcessingException jpe) { +// jpe.printStackTrace(); +// } + return null; } }