Successfully map s3Event

main
Hammy 3 years ago
parent 3ec134de81
commit ff92580e71

@ -21,13 +21,18 @@ micronaut {
dependencies { dependencies {
implementation("io.micronaut:micronaut-runtime") implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.xml:micronaut-jackson-xml")
implementation("javax.annotation:javax.annotation-api") 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("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-core:1.2.1")
implementation("com.amazonaws:aws-lambda-java-events:3.9.0") implementation("com.amazonaws:aws-lambda-java-events:3.9.0")
runtimeOnly("ch.qos.logback:logback-classic")
} }

@ -1,28 +1,50 @@
package com.example; package com.example;
import com.amazonaws.services.lambda.runtime.events.S3Event;
import com.amazonaws.services.lambda.runtime.events.SNSEvent; 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.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.micronaut.function.aws.MicronautRequestHandler; import io.micronaut.function.aws.MicronautRequestHandler;
import jakarta.inject.Inject; import jakarta.inject.Inject;
public class TestRequestHandler extends MicronautRequestHandler<SNSEvent.SNS, Void> { public class TestRequestHandler extends MicronautRequestHandler<SNSEvent, Void> {
@Inject @Inject
ObjectMapper objectMapper; ObjectMapper objectMapper;
@Override @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 { try {
S3Event s3Event = objectMapper.readValue(input.getMessage(), S3Event.class); S3EventNotification s3EventNotification = objectMapper.readValue(input.getRecords().get(0).getSNS().getMessage(), S3EventNotification.class);
String message = s3Event.toString(); String message = s3EventNotification.toString();
System.out.println(message); 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) { } catch (JsonProcessingException jpe) {
jpe.printStackTrace(); jpe.printStackTrace();
} }
// try {
// Map<String, String> map = objectMapper.readValue(input.getRecords().get(0).getSNS().getMessage(), new TypeReference<HashMap<String,String>>() {});
// 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; return null;
} }
} }

Loading…
Cancel
Save