Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

amazon web services - AWS event driven approach - Cloud Watch vs S3 event notification

I am building an event-driven system, which starts as soon as a new file lands S3. I am evaluating different ways of achieving that and using Cloud Watch Rule + API Trail is an option. This is the Cloud Watch Event pattern as it is:

    {
  "source": [
    "aws.s3"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "s3.amazonaws.com"
    ],
    "eventName": [
      "PutObject"
    ],
    "requestParameters": {
      "bucketName": [
        "mysupertest88"
      ]
    }
  }
}

Like that, it triggers the rule for every file landing into the bucket but trying to filter by key and wildcard does not work:

"requestParameters": {
      "bucketName": [
        "mysupertest88"
      ],
      "key": ["myprefix/mysecondprefix/*"]
    }

It works just if I specify a key with matches without a wildcard, I think because the symbol '*' is a valid char in S3 objects. An alternative is to filter directly at Trail level: API Trail

but I do not see that as a nice option, as API Trail is often out of developer's control. An additional alternative is to use content-filtering: (nice new feature, but you have to create the rule through EventBridge)

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

Last S3 event notification is the old way to accomplish this? What is your experience with that? Any pro and cons that are not easy to catch without experience?

question from:https://stackoverflow.com/questions/65641437/aws-event-driven-approach-cloud-watch-vs-s3-event-notification

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since your objective is to start an action "as soon as a new file lands S3", CT may not satisfy your requirement. This is because it can take up 15 minutes for delivery of the API events. From AWS faq:

Typically, CloudTrail delivers an event within 15 minutes of the API call.

In contrast, S3 events should be faster. From AWS docs:

Amazon S3 event notifications are designed to be delivered at least once. Typically, event notifications are delivered in seconds but can sometimes take a minute or longer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...