Home > Software design >  get notified if objects is there in a particular folders of a s3 bucket for more than 7 hours
get notified if objects is there in a particular folders of a s3 bucket for more than 7 hours

Time:10-13

I have a lambda to process the files in a folder of a s3 bucket. I would like to setup an alarm/notification if objects are in the folders for more than 7 hours and not processed by the lambda

CodePudding user response:

You can use the tags of objects in S3, have something like tag name Processed : true or false changed by your lambda processor.

Then in your another scheduled lambda you can check the creation object if > 7h and processed : false (that means not processed by the lambda), if found you create a notification in SNS

CodePudding user response:

Set object expiration to 7 hours for the S3 bucket. Then have a lambda get triggered by the delete event. The lambda can be one that notifies you and saves the file into another bucket or forwards it to your original lambda. The lambda triggered could be the one that should have been triggered when uploading the object.

Alternatively, you can add tags to the uploaded files. A tag could be ttl: <date-to-delete>. You have a CloudWatch scheduled event that runs a lambda, for instance every hour, and checks for all objects in the S3 bucket whether the ttl-tag's value is older than the current time.

Personally, I would go with the first approach as it's more event driven and less scheduled processing.

On another note, it's rather strange that the lambda doesn't get triggered for some S3 objects. I don't know how you deploy your Lambda and configure the trigger to S3. If you're using serverless or CDK I don't see how your lambda doesn't get triggered for every uploaded file with a configuration similar to the following:

// serverless example
functions:
  users:
    handler: users.handler
    events:
      - s3:
          bucket: photos
          event: s3:ObjectCreated:*
          rules:
            - prefix: uploads/
            - suffix: .jpg

In this example the users lambda gets triggered for every jpg file that gets created in photos/uploads.

  • Related