Created
January 6, 2017 13:48
-
-
Save petarjs/03a5274e729bbbc9df392e4a790b36cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = function(event, context) { | |
var sampleInput = { | |
totalPhotos: 496, | |
imagesPerLambda: 100, | |
bucketName: 'sample-bucket', | |
imageSizes: [{ | |
width: 600, | |
height: 400, | |
description: 'A medium thumbnail', | |
prefix: 'thumb-', | |
suffix: '-600x400' | |
}, { | |
width: 200, | |
height: 100, | |
description: 'A mini thumbnail', | |
prefix: 'thumb-', | |
suffix: '-200x100' | |
}], | |
sns: { | |
channelName: 'test-channel' | |
} | |
}; | |
var numberOfChunks = Math.ceil(sampleInput.totalPhotos / sampleInput.imagesPerLambda); | |
var chunks = _.range(0, numberOfChunks); | |
var chunksBounds = _.map(chunks, function(chunk) { | |
var from = chunk * sampleInput.imagesPerLambda + 1; | |
var to = (chunk + 1) * sampleInput.imagesPerLambda > sampleInput.totalPhotos | |
? sampleInput.totalPhotos | |
: (chunk + 1) * sampleInput.imagesPerLambda; | |
return { | |
from: from, | |
to: to | |
}; | |
}); | |
var lambdaInvokeOptions = _.map(chunksBounds, function(bounds) { | |
return _.merge({}, bounds, { | |
bucketName: sampleInput.bucketName, | |
imageSizes: sampleInput.imageSizes | |
}); | |
}) | |
// SNS is a simple wrapper around AWS SNS Node library | |
var publishToChannel = SNS.publish(sampleInput.sns.channelName); | |
_.each(lambdaInvokeOptions, publishToChannel); | |
context.done(null, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment