5

I'd like to write a Lambda function that is triggered when files are added or modified in an s3 bucket and processes them and moves them elsewhere, clobbering older versions of the files.

I'm wondering if AWS Lambda can be configured to trigger when files are updated?

After reviewing the Boto3 documentation for s3 it looks like the only things that could happen in a s3 bucket would be creations and deletions.

Additionally, the AWS documentation seems to indicate there is no way to trigger things on 'updates' to S3.

Am I correct in thinking there is no real concept of an 'update' to a file in S3 and that an update would actually be when something was destroyed and recreated? If I'm mistaken, how can I trigger a Lambda function when an S3 file is changed in a bucket?

3
  • Did you read this eng.localytics.com/… Sep 14, 2016 at 23:09
  • @error2007s no but the linked post which I did read seems to indicate there is no concept of 'updates' aws.amazon.com/blogs/aws/s3-event-notification But the quote in your link shows 'Lambda will automatically run code in response to modifications to objects uploaded to Amazon Simple Storage Service (S3) buckets'. 'Modifications' is the language here but I can only assume that actually means newly created objects?
    – Fernando
    Sep 14, 2016 at 23:15
  • Objects will be modified when we rewrite that object by uploading a new version? Sep 14, 2016 at 23:20

2 Answers 2

10

No, there is no concept of updating a file on S3. A file on S3 is updated the same way it is uploaded in the first place - through a PUT object request. (Relevant answer here.) An S3 bucket notification configured to trigger on a PUT object request can execute a Lambda function.

4

There is now a new functionality for S3 buckets. Under properties there is the possibility to enable versioning for this bucket. And if you set a trigger for creating on S3 assigned to your Lambda function - this will executed every time if you 'update' the same file as it is a new version.

1
  • The versioning functionality does not seem to add a specific update trigger event. I have checked S3 buckets with or without versioning, and the event list is the same. So, it does not allow to specifically target file updates. Additionally, there is no need to enable versioning to set a trigger when a file is replaced by another one. Without versioning, POST / PUT event is triggered for new files, but also for files replacing older ones.
    – Jeremie
    Jun 2, 2021 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.