amazon-web-servicesamazon-s3aws-lambdaamazon-cloudwatcheventtrigger

How to trigger a lambda function when a file is downloaded from a s3 bucket?


I am aware of triggering when a file is uploaded into a bucket. But how do we trigger a lambda function when a file is downloaded from a s3 bucket. I have been trying using server logs and cloud watch but couldn't find the solution.


Solution

  • Currently S3 dosen't support read events.

    However, their can be 2 approaches to solve the issue.

    1. Use cloudTrail to track api call which reads S3 object and create an alarm on event which in turn triggers the lambda.

    S3 --> CloudTrail (Read Call) --> CloudWatch Event --> Lambda

    or otherwise

    1. Just don't give access to bucket directly and control the downloads via lambda itself.