Trigger lambda only on S3 object create, but not to trigger on override

0

We had a use case to trigger the AWS Lambda from S3 for the objects which are created for the first time. We don't want the lambda to be triggered for the object overrides. I checked the documentation for S3 POST and PUT, both looks similar.

質問済み 2年前1607ビュー
1回答
1
承認された回答

There's no particularly easy way to do what you want to do here. PUT/POST events both send out events for object creation even when they are replacing existing objects.

You could enable versioning on the bucket and detect (by looking at the object metadata) whether there is a new version that has just been uploaded. But it would mean that you'd have extra copies of objects in the buckets. Those could be deleted using lifecycle rules but it's extra work to do.

Even more work would be to maintain a database which holds a list of existing objects; the Lambda function would check to see if this is a replace operation rather than a "proper" creation and stop running as appropriate.

That said, if you already have a database (or list or something) which you're trying not to populate with additional data when the objects are replaced then maybe you could query that? If the object doesn't exist in that store then it is new; otherwise it is a replacement.

profile pictureAWS
エキスパート
回答済み 2年前
profile picture
エキスパート
レビュー済み 1ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ