Skip to content

Instantly share code, notes, and snippets.

@andy51002000
Last active September 1, 2018 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy51002000/e9bff5bd764b362de4836629ddb6db00 to your computer and use it in GitHub Desktop.
Save andy51002000/e9bff5bd764b362de4836629ddb6db00 to your computer and use it in GitHub Desktop.
SQS Lambda poll code
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