How to trigger an AWS Event Rule when a S3 key with a specific suffix gets uploaded

Viewed 4093

I'm trying to create an AWS Event Rule that is only triggered when a file with a specific suffix is uploaded to an S3 bucket.

{
  "source": [
    "aws.s3"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "s3.amazonaws.com"
    ],
    "eventName": [
      "PutObject",
      "CompleteMultipartUpload"
    ],
    "requestParameters": {
      "bucketName": [
        "bucket-name"
      ],
      "key": [
        { "suffix": ".csv" }
      ]
    }
  }
}

As I understand there AWS has content-based filtering which can be used but docs doesn't show the ability to use a suffix, only prefix among other patterns: https://docs.aws.amazon.com/eventbridge/latest/userguide/content-filtering-with-event-patterns.html

Ideally I could be able to do it here without the need for an intermediary Lambda as my event target is an ECS Fargate task.

1 Answers

At this time (July 2020) CloudWatch events does not appear to have suffix filtering built into it.

You could instead configure an S3 Event Notification which do support the ability to specify prefixes and suffixes.

By using an S3 event notification you can still have your target as a Lambda.

Related