Is there a way within SST to trigger a Function af...
# help
d
Is there a way within SST to trigger a Function after someone accesses a file from a bucket? For example, to track customer’s’ user’s access to resources for billing purposes. It seems to me this would be the easiest way - but I’m new to this serveless stuff. I’m trying to avoid to create an API endpoint and to do it on resource access directly.
f
hmm not that i’m aware of. Afaik, you can only listen to these S3 events https://docs.aws.amazon.com/AmazonS3/latest/userguide/NotificationHowTo.html
d
I’m looking into this one:
It’s in the behaviour of the CloudFront. The goal would be for: 1. GET cloudfront.com/myfile.txt 2. client -> CDN -> S3 -> spawn NON blocking lambda -> CDN -> client
f
ah if u r using CloudFront, yeah this could work
d
hum I just realised that the CDN created isn’t for the bucket, but for the reactsite
I guess I can get that to work by adding a cdn to our bucket with CDK directly
f
yeah what are u storing in the S3 bucket?
d
3D model files. high level: Our app is an AR widget that handles AR for iOS and Android. So our public bucket has for each widget 2 models android.3d and apple.3d. We want to track access to those files and bill the customer per click
The goal is for the customer to embed that widget on its website and its users will load it and click on 3d files and we need to track it for analytics purposes and billing.
f
I see. Yeah CF would work. You could also not make the 3D models public, and users have to call an API to generate pre-signed url for the files they need to access.
The CF makes more sense, as u will be benefiting from CDN caching. Just that Lambda@Edge functions are a bit annoying to manage.
d
The reason we didn’t go with the API is to get it the fastest possible for the end user. Speed is king in this area. They embed the widget with
<widget id="foo />
that loads its styles from
<http://cdn.com/foo/widget.json|cdn.com/foo/widget.json>
and on click it will directly open the file
<http://cdn.com/foo/apple.3d|cdn.com/foo/apple.3d>
Instead of checkin on each request quotas and creating analytics events, we want to do it after the request is done to eliminate that processing from the request. This creates the problem that some files are accessed outside their quote but in reality, having the user accessing 1'000'010 times instead of 1M is not a big deal.
And now that I wrote that down I just realised that CDN function will anyway execute BEFORE returning the result…
f
d
@Daniel Gato I’m very familiar with Lambda@Edge functions and the various ways to leverage them. Feel free to pick my brain. I’m also very interested in how best to do what you are trying to do. Coincidentally, we’re looking to track file usage as well. I seem to recall a way to setup s3 quota/analytics a different way… and still need to google.