What the best way I can catch get and Put Operation in and Out S3 bucket, in such a way as to be able to introduce processing logic?

0

Hi, i'm searchin for a solution to execute custom code on S3 putting and getting event objects, like custom encrypt/decrypt data, interact with DB/services (...). At this moment the solution I'm considering is

PUT

  1. Client: Asset => presignedUrl => S3
  2. Trigger : . generate AssetEncrypted from Asset . execute other custom logic . delete Asset

GET

  1. Client: GetObject Request => S3 Object Lambda
  2. S3ObjectLambda execute some logic and Process and Decrypt Asset Encrypt
  3. Return Asset

For Put i'm also considering S3 Transfer Family, maybe for his capacity of manage pre-processing assets, but i guess this is not a good choice. Can You give me a suggest?

asked 7 months ago259 views
2 Answers
0

If i understood correctly, you want to execute code when a customer does put /get. Right? You can do this with an EventBridge rule that triggers a lambda and the lambda executes the logic, performs XYZ . Check Using Eventbridge for S3 .

So, you create a rule for PUT Object with target a lambda that does <generate AssetEncrypted from Asset . execute other custom logic . delete Asset>. The rule pattern can look like this for a bucket called 'test1':

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

Then you create a rule for GET object, that has another lambda as a target and performs as above, the logic you need. The rule pattern would be:

{
  "source": ["aws.s3"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["s3.amazonaws.com"],
    "eventName": ["GetObject"],
    "requestParameters": {
      "bucketName": ["test1"]
    }
  }
}
Natassa
answered 7 months ago
0

Hi, The way you suggest to catch event on S3 is perfect for post processing, i think,

https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html

i'm searching a method for inserting custom code on asset before requests are processed. E. G. before putting the item in the store I would like to process file (encrypt, update DB from metadata parsed, validation, etc...). ; before i get Object from store (decrypt, etc...), etc... In any case, thank you, I will try to search better also among the possibilities of EventBridge, since you recommend it

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions