Last active
September 1, 2018 08:55
-
-
Save andy51002000/e9bff5bd764b362de4836629ddb6db00 to your computer and use it in GitHub Desktop.
SQS Lambda poll code
This file contains 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
var AWS = require('aws-sdk'); | |
exports.handler = function(event, context, callback) { | |
var sqs = new AWS.SQS({ apiVersion: "2017-12-29" }); | |
var queueURL = "https://sqs.us-east-1.amazonaws.com/1234567890/Tasks"; | |
var params = { | |
AttributeNames: ["SentTimestamp"], | |
MaxNumberOfMessages: 1, | |
MessageAttributeNames: ["All"], | |
QueueUrl: queueURL, | |
VisibilityTimeout: 2, | |
WaitTimeSeconds: 0 | |
}; | |
sqs.receiveMessage(params, (err,data)=>{ | |
if(err){ | |
console.log(err); | |
}else | |
{ | |
console.log("Received Data:",data); | |
sqs.deleteMessage(deleteParams, function(err, data) { | |
if (err) { | |
console.log("Delete Error", err); | |
} else { | |
console.log("Message Deleted", data); | |
} | |
}); | |
} | |
}) | |
var count = 0; | |
var x = setInterval(()=>{ | |
count ++; | |
console.log("process " +count); | |
if(count >10){ | |
clearInterval(x); | |
console.log('task end') | |
callback(); | |
} | |
},1000) | |
console.log('lambda end') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment