Created
March 25, 2021 16:23
-
-
Save oxlb/20f2e7ce294fc4adedd85ac0b989a160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Load the AWS SDK for Node.js | |
const AWS = require('aws-sdk'); | |
// Set the region | |
AWS.config.update({region: 'ap-southeast-1'}); | |
const config = { | |
endpoint: new AWS.Endpoint('http://localhost:4566'), | |
accessKeyId: 'na', | |
secretAccessKey: 'na', | |
region: 'ap-southeast-1' | |
} | |
const QUEUE_NAME = 'onexlab'; | |
const QUEUE_URL = 'http://localhost:4566/000000000000/onexlab'; | |
// Create an SQS service object | |
const SQS = new AWS.SQS(config); | |
const listParams = {}; | |
const createParams = { | |
QueueName: QUEUE_NAME, | |
Attributes: { | |
'DelaySeconds': '60', | |
'MessageRetentionPeriod': '86400' | |
} | |
}; | |
const msgParams = (msg) => { | |
return { | |
// Remove DelaySeconds parameter and value for FIFO queues | |
DelaySeconds: 10, | |
MessageAttributes: { | |
"Title": { | |
DataType: "String", | |
StringValue: "The Whistler" | |
}, | |
"Author": { | |
DataType: "String", | |
StringValue: "John Grisham" | |
}, | |
"WeeksOn": { | |
DataType: "Number", | |
StringValue: "6" | |
} | |
}, | |
MessageBody: msg, | |
// MessageDeduplicationId: "TheWhistler", // Required for FIFO queues | |
// MessageGroupId: "Group1", // Required for FIFO queues | |
QueueUrl: QUEUE_URL | |
} | |
}; | |
const receiveParam = { | |
AttributeNames: [ | |
"SentTimestamp" | |
], | |
MaxNumberOfMessages: 10, | |
MessageAttributeNames: [ | |
"All" | |
], | |
QueueUrl: QUEUE_URL, | |
VisibilityTimeout: 20, | |
WaitTimeSeconds: 0 | |
}; | |
module.exports = { | |
SQS, | |
QUEUE_NAME, | |
QUEUE_URL, | |
listParams, | |
createParams, | |
msgParams, | |
receiveParam | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment