Using SQS in Windows
It is easy.
First: configure your credentials.
After the login, click as the image bellow:
After this step, select the credentials of the option 2:
Put the content in c:\users\<user>\.aws\credentials, replacing the content of the first line by “[default]” (without quotes).
Create the queue:
Click in “Management Console”
In the link of the services (next page, click in SQS — Simple Queue Service). Maybe you need to use the search bar.
Click in “Create queue” (“criar fila” in portuguese). Use the default values.
After create a queue, create an Node.js file (e.g.: index.js with the content bellow:
// Load the AWS SDK for Node.js
var AWS = require(‘aws-sdk’);
var credentials = new AWS.SharedIniFileCredentials({profile: ‘default’});
AWS.config.credentials = credentials;
// console.log(credentials)
// Set the region
AWS.config.update({region: e.g.:‘us-east-1’});
// Create an SQS service object
var sqs = new AWS.SQS({apiVersion: ‘2012–11–05’});
var params = {
// 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: “Information about current NY Times fiction bestseller for week of 12/11/2016.”,
// MessageDeduplicationId: “TheWhistler”, // Required for FIFO queues
// MessageGroupId: “Group1”, // Required for FIFO queues
QueueUrl: <queue URL>
};
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log(“Error”, err);
} else {
console.log(“Success”, data.MessageId);
}
});
If you will see that some parts have no sense (JavaScript has no “e.g.:”, that is in the script), you are right. When you paste the code you need to adjust some things, like remove the “e.g.:”, and replace some chars (single and double quotes) by the corect chars. I tested this post and what I say here works :).
Well, you will need a new Node.JS project. You will obtain it with the command bellow:
npm init
After the project initializated, install the AWS SDK:
npm i — save aws-sdk
Now we need to send a message. Execute this script (e.g.):
node index.js
You can see the message online after send it:
Click in “find messages”. Thadãããã!! The message is there:
Click in one message to see the content:
That’s all…