Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. exports.handler = function(event, context) {
  2.  
  3. var sampleInput = {
  4. totalPhotos: 496,
  5. imagesPerLambda: 100,
  6. bucketName: 'sample-bucket',
  7. imageSizes: [{
  8. width: 600,
  9. height: 400,
  10. description: 'A medium thumbnail',
  11. prefix: 'thumb-',
  12. suffix: '-600x400'
  13. }, {
  14. width: 200,
  15. height: 100,
  16. description: 'A mini thumbnail',
  17. prefix: 'thumb-',
  18. suffix: '-200x100'
  19. }],
  20. sns: {
  21. channelName: 'test-channel'
  22. }
  23. };
  24.  
  25. var numberOfChunks = Math.ceil(sampleInput.totalPhotos / sampleInput.imagesPerLambda);
  26. var chunks = _.range(0, numberOfChunks);
  27.  
  28. var chunksBounds = _.map(chunks, function(chunk) {
  29. var from = chunk * sampleInput.imagesPerLambda + 1;
  30. var to = (chunk + 1) * sampleInput.imagesPerLambda > sampleInput.totalPhotos
  31. ? sampleInput.totalPhotos
  32. : (chunk + 1) * sampleInput.imagesPerLambda;
  33.  
  34. return {
  35. from: from,
  36. to: to
  37. };
  38. });
  39.  
  40. var lambdaInvokeOptions = _.map(chunksBounds, function(bounds) {
  41. return _.merge({}, bounds, {
  42. bucketName: sampleInput.bucketName,
  43. imageSizes: sampleInput.imageSizes
  44. });
  45. })
  46.  
  47. // SNS is a simple wrapper around AWS SNS Node library
  48. var publishToChannel = SNS.publish(sampleInput.sns.channelName);
  49. _.each(lambdaInvokeOptions, publishToChannel);
  50.  
  51. context.done(null, true);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement