1

I currently have an S3 bucket configured to enable EventBridge events and I have an EventBridge rule that triggers a step function that in turn triggers a lambda.

I want to map the input I'm getting in the lambda to one of the event classes in the AWS Java SDK (com.amazonaws:aws-lambda-java-events) but I'm not having much luck.

Here is the signature of my lambda in my Java code:

public class DeviceAssociationLambda implements RequestHandler<S3Event, OutputObject> {
    @Override
    public OutputObject handleRequest(S3Event input, Context context) {

When my step function invokes this lambda, it's sending a payload that looks like this:

{
  "version": "0",
  "id": "e31fcb40-aa08-11ec-b909-0242ac120002",
  "detail-type": "Object Created",
  "source": "aws.s3",
  "account": "123456789098",
  "time": "2022-03-22T17:07:44Z",
  "region": "eu-central-1",
  "resources": [
    "arn:aws:s3:::my-test-bucket"
  ],
  "detail": {
    "version": "0",
    "bucket": {
      "name": "my-test-bucket"
    },
    "object": {
      "key": "foo/bar.json",
      "size": 685,
      "etag": "af87c63487cc2ff6323e67ddd234f44",
      "sequencer": "00827F2232287F2343"
    },
    "request-id": "LK63256WW7E66YCC4",
    "requester": "123456789098",
    "source-ip-address": "123.123.123.123",
    "reason": "PutObject"
  }
}

After trying to debug this, I see that the S3Event parameter into my lambda is always empty. This is probably because it is expecting the input JSON in some different format (probably this: https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html)

So, my question is, is there any standard event object in the Java SDK that would handle the JSON I'm getting from EventBridge? I can, of course, manipulate the JSON a bit in the step function, such as limiting the lambda input to the "detail" block if that helps.

Or will I just have to create my own input class that maps to this JSON structure that I'm getting as input?

StFS
  • 1,639
  • 2
  • 15
  • 31

2 Answers2

2

I found this issue: https://github.com/aws/aws-lambda-java-libs/issues/109

So it seems clear to me that the Event Bridge events have a format of their own which is not currently supported by the Java SDK event library but it's being worked on.

However, the Event Bridge event is defining the top level elements in the JSON message I'm receiving, but I'm still a bit unclear on what the format inside the "details" element is for my S3 ObjectCreated event is and whether there exists some class in the Java SDK somewhere that I can use for that.

StFS
  • 1,639
  • 2
  • 15
  • 31
-1

Check out this post - Link

    Configuration conf =
            Configuration
                    .defaultConfiguration()
                    .setOptions(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS);
    DocumentContext document = JsonPath.using(conf).parse(input);
    String bucketName  = document.read("$.detail.bucket.name");
    String objectKey = document.read("detail.object.key");
    s3BucketInfo.put(CLAIMS_S3_BUCKET_NAME, bucketName);
    s3BucketInfo.put(CLAIMS_S3_SOURCE_OBJECT_KEY, objectKey);