简体   繁体   中英

Create AWS CloudWatch Event rule for S3 prefix

I wish to create an AWS CloudWatch Event rule for S3 create events, in a specific bucket and prefix. Since CloudWatch does not support wildcards, I am instead trying to give the prefix explicitly as in the following example: Does AWS CloudWatch Events Rule supports any wildcards in S3 bucket/key names

(for obfuscation I provide the bucket and prefix names here as my-data-bucket and my-data-prefix/ )

My JSON rule:

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

Yields the error:

Event pattern contains invalid element (can only be Strings enclosed in quotes, numbers, and the unquoted keywords true, false, and null)

This might be that the curly braces are not allowed for the key request parameter, but how can you create a rule to listen to just a specific prefix, without being allowed wildcards? (and preferably without having to customize the CloudTrail trail as in Cloudwatch event rule listen to s3 bucket with specific keypath )

Your event is invalid in CloudWatch Events (CWE) rule, but should be fine for CWE replacement, ie AWS EventBridge (EB). Thus I would recommend using EB for that event.

EB is basically a new version of CWE, so you can do same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM