ensure-queue
v0.5.0
Published
We love queues and use AWS. This code creates (if necessary) an AWS SQS queue and calls the callback, giving you an SQS queue URL with ease.
Downloads
4
Readme
EnsureQueue
We love queues and use AWS. This code creates (if necessary) an AWS SQS queue and calls the callback, giving you an SQS queue URL with ease.
The creation of queues is an unnessary peice of admin that you shouldn't have to worry about, but your code will error if it doesn't already exist. This code will create an AWS SQS queue if it is not already set up and also caches the fact that the queue now exists. If it already existed it just moves on and feeds you the correct SQS URL.
When queues are created the options passed in the fourth argument will be used but it will not alter already existing queues.
const QUEUE_ENV = 'prod';
const AWS_REGION = 'eu-west-1';
var sqs = new AWS.SQS({
region: AWS_REGION,
maxRetries: 3
});
var ensureQueue = new EnsureQueue(
sqs, // SQS instance
QUEUE_ENV, // Will be prepended to every queue created
'-', // The seperator for queue names
{MessageRetentionPeriod: '1209600' /* yes it needs to be a string! */} // Passed through to `sqs` when creating new queues.
);
ensureQueue.ensureQueue('worker', 'development', function(err, url) {
if (err) { return next(err); }
console.log(url); // = https://sqs.eu-west-1.amazonaws.com/123456789/prod-worker-development
});