Skip to content

Instantly share code, notes, and snippets.

@badlands
Created April 24, 2020 11:00
Show Gist options
  • Save badlands/3170076399f545efbbeead35a799c052 to your computer and use it in GitHub Desktop.
Save badlands/3170076399f545efbbeead35a799c052 to your computer and use it in GitHub Desktop.
How to send messages on a SQS queue with Node.js
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({
accessKeyId: '....',
secretAccessKey: '....',
region: 'eu-central-1'
});
// Create an SQS service object
var sqs = new AWS.SQS();
const MESSAGE = {
"game_api_name": "...",
"user_id": 1,
"type": "action",
"id": "...",
"received_at": "2018-05-04T04:03:30Z"
};
var params = {
DelaySeconds: 10,
MessageAttributes: {},
MessageBody: JSON.stringify(MESSAGE),
QueueUrl: "...."
};
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.MessageId);
}
});
// snippet-end:[sqs.JavaScript.messages.sendMessage]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment