I want to create a s3 trigger that calls an api when someone tries to access/download a file stored in s3.
I saw some usecases for s3 trigger only for creating and deleting files. But couldnot find triggers when someone tries to access a file from s3.
2
Answers
You can use cloudtrial for that as explained in Logging Amazon S3 API calls using AWS CloudTrail. So you would settup a trial in CloudTrial to monitor
GetObject
S3 event objects, which you can then detect as events in AWS EventBridge.Other possibility would be through S3 Object Lambda.
Amazon S3 does not provide the ability to intercept requests, but you could send requests via Amazon CloudFront and Use AWS Lambda with CloudFront Lambda@Edge – AWS Lambda to intercept the calls and determine what to do. Lambda@Edge functions are limited in what they can do and how long they can run.
Alternatively, you could send the requests to your own API endpoint (eg using API Gateway or a Lambda URL). You can then write code that examines the request and determines what to do.