I am trying to create a lambda function that counts how many times an asset (in this case an mp4 file) is accessed from s3. This will be used to update a db that stores the views for each file. Trying to used lambda@edge to get viewer request triggers has caused the lambda to be triggered a different amount of times depending on if you're on mobile vs desktop or on different browsers. This is due to the fact that the request from each browser looks different. I figured I could have clauses for each type of browser request but I feel like that isn't a very good approach. Tips for ensuring each request will only trigger the lambda once?
Asked
Active
Viewed 124 times
0

John Rotenstein
- 241,921
- 22
- 380
- 470

Michael Goodrum
- 69
- 3
-
1If you don't need real-time tracking, you could use [Amazon S3 Server Access Logs](https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html) to retrieve access requests. – John Rotenstein Nov 26 '18 at 18:31
-
[CloudFront access logs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html) might be a better choice, since the S3 logs will not catch cache misses... but while we are at it, are you sure about the behavior you are seeing? `event.Records[0].cf.config.requestId` is a unique ID you can cross-validate between viewer-side triggers and the CloudFront logs. If you are seeing multiple (redundant) requests from some devices, you should investigate and understand why that happens, what it means, and whether it can perhaps be avoided. – Michael - sqlbot Nov 26 '18 at 20:15