Reputation: 7057
I've got a Lambda function that writes a file to S3 and then returns a signed-url to that file. Within my angular app this value is received and immediately gone to in order to download the file from S3. After the file is downloaded I want it deleted from S3.
I know I can trigger the deletion from the Angular application, but I'd really like the deletion not to be dependent on the client so that I know it actually happens. What is the best way to handle this?
I would think that deleting the file 15-30 seconds after the URL is returned is probably really safe, but I'm not sure the best way to trigger this with Lambda.
I was thinking of using a setInterval, but that seems messy since I'm keeping Lambda running for quite a bit longer than it needs to run.
Are there any cleaner options that aren't overly complicated?
I already have an expiration on the S3 bucket, but the shortest interval you can set on that is 1 day. That is much longer than I'd like to keep the item around.
Upvotes: 4
Views: 4431
Reputation: 947
Best way to do this is by using S3 events that can trigger Lambda directly after a download. If an additional delay is required, you could also make the S3 event go to an SQS queue first (with settings to delay message delivery by x time) and let the SQS queue trigger a new lambda function for the removal.
Upvotes: 1