Home > OS >  Lambda listening to s3 events should trigger file processing API only after receiving all files in b
Lambda listening to s3 events should trigger file processing API only after receiving all files in b

Time:06-23

Lambda which listens to s3 events. We will receive three files in s3 bucket and lambda should trigger the file processing API call only after receiving three files in the bucket.

My approach:

Create a counter table in DynamoDB with Date,count as items

Every time we receive a s3 event, Retrieve the count value from table and if value is less than 3 Add/Update entry for Date and increase the count value.

Once the count = 3 , trigger the file processing API.

Any help is appreciated. Please correct if my approach have issues.

CodePudding user response:

Your situation appears to be:

  • Files are being created in an Amazon S3 bucket
  • You have an AWS Lambda function that will process the files
  • The Lambda function is configured to run when an object is created in the S3 bucket
  • However, you only want to process the files after they have "all" been uploaded to S3

The Lambda function will be triggered after every object is created. You should add code to the start of the Lambda function that checks whether all of the desired objects are present (eg by listing the contents of the bucket and path). If so, it can process the objects and then delete them.

  • Related