Reputation: 85
Currently i have two buckets in S3 - let's call them buck
and buck_thumb
. Right now, when i uploads an image in to the buck
bucket, which triggers a lambda function that resizes the image into a thumbnail and uploads the thumbnail into the buck_thumb
bucket.
But now i want to make it like - when i send a image url in buck
bucket then it download the image and re size it .
Is there a way ? I can do this using only one bucket?
Upvotes: 3
Views: 2863
Reputation: 11
If you do it simply, then you upload -> resize -> upload -> resize..... unlimited loop. So, you should filter the size of the image. If the image already has been the proper size, stop the function.
gm(data.Body)
.size(function (err, size) {
if(err){
callback('gm(data.Body) error');
context.fail(err);
}
if (size.width <= resizeWidth && size.height <= resizeHeight) {
console.log('already resized')
context.succeed({
"error":false
});
}
});
Upvotes: 1
Reputation: 66
What I do is I set the lambda function to SNS Message Event, so when I upload to an S3 bucket I send from my server a SNS message to the configured url, and the message is the entire path on S3 to the file, so Lambda can download it, resize it and then upload with thumb_ or whatever.
Hope it helps! This is 4 months ago, but... I hope it helps future visitors XD
Upvotes: 5