SHARE
TWEET

SQS2Dynamo_v3

a guest Feb 14th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const aws = require( 'aws-sdk' );
  2. const sqs = new aws.SQS({apiVersion: '2020-02-13'})
  3. const db = new aws.DynamoDB.DocumentClient();
  4.  
  5. var licznik = 0;
  6.  
  7. function receiveMessages(callback) {
  8.   var params = {
  9.     QueueUrl: 'https://sqs.us-east-1.amazonaws.com/003269188493/DaneWifiQueue2.fifo',
  10.     MaxNumberOfMessages: 10
  11.   };
  12.   sqs.receiveMessage(params, function(err, data) {
  13.     if (err) {
  14.       console.error(err, err.stack);
  15.       callback(err);
  16.     }
  17.     else if (data.Messages){
  18.       for (var i = 0; i < 10; i++) {
  19.         var params = {
  20.           TableName: 'DaneWifiTable',
  21.           Item: {
  22.             lokacja : data.Messages[i].Body
  23.           }
  24.         };
  25.         licznik++;
  26.         var id = 'nr' + parseInt(licznik);
  27.         params.Item.klucz = id;
  28.         db.put(params).promise();
  29.       }
  30.     }
  31.       callback(null, data.Messages);
  32.   });
  33. }
  34.  
  35. exports.handler = function(event, context, callback) {
  36.   for (var j = 0; j < 10; j++) {
  37.     receiveMessages(callback);
  38.   }
  39. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top