Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement