# NodeJS 1 - install sdk package in to your directory (make sure that Node.js is install in your machine) ```javascript npm install @aws-sdk ``` You can install specific package which is required , like right now we are working on SQS so we can install SQS. ```javascript npm install @aws-sdk/client-sqs ``` 2 - Make a connection with the EQS client. To make the connection with the EQS client , you need to pass configurations and credentials. **Configurations-** ```javascript region_name = your_region endpoint_url = eqs_endpoint_url (provided by e2e networks eqs service) ``` **Credentials-** ```javascript aws_access_key_id = your_access_key_id aws_secret_key_id = your_secret_key_id ``` ## Make Connection with EQS there are many ways to make connection with eqs_client **a)** You can directly pass the credentials and configurations at the time of making a session with the EQS client. **warning** - *Hardcoded credentials in application is not recommended* *create a new file named* **index.js** ```javascript import {SQSClient} from “@aws-sdk/client-sqs” REGION = “your_region” ENDPOINT = “endpoint_provided_by_E2E“ ACCESSKEYID = “access_key_id“ SECRETACCESSKEY = “your_secret_access_key“ const eqs_client = new SQSClient( { region : REGION, endpoint : ENDPOINT, credentials : { accessKeyId : ACCESSKEYID, secretAccessKey : SECRETACCESSKEY } }); ``` **b)** you can put credentials and configurations in the config and credentials file , and these files should be located at ~/.aws/config, ~/.aws/credentials location. *put credentials into* **~/.aws/credentials** *file* ```javascript [default] aws_access_key_id=”access_key_id” aws_secret_access_key=”secret_key “ ``` *put config into* **~/.aws/config** *file* ```javascript [default] region =”region“ ``` *create a new file named* **index.js** ```javascript import {SQSClient} from “@aws-sdk/client-sqs” ENDPOINT = “eqs_endpoint_url_provided_by_e2e“ const eqs_client = new SQSClient( { endpoint : ENDPOINT }); ``` **c)** you can make the connection with the EQS client by passing the credentials and configuration into the **environment variables** file. *install dotenv* ```javascript npm install dotenv ``` *using terminal* **(Linux, OS X or Unix)** ```javascript $ export AWS_ACCESS_KEY_ID = your_access_key_id $ export AWS_SECRET_ACCESS_KEY = your_secret_key $ export AWS_DEFAULT_REGION = your_eqs_region $ export ENDPOINT = end_point_url ``` *using terminal* **(Windows)** ```javascript > set AWS_ACCESS_KEY_ID = your_access_key_id > set AWS_SECRET_ACCESS_KEY = your_secret_key > set AWS_DEFAULT_REGION = your_eqs_region > set ENDPOINT = end_point_url ``` **or,** *edit your environment variable file* ```javascript AWS_ACCESS_KEY_ID = your_access_key_id AWS_SECRET_ACCESS_KEY = your_secret_access_key AWS_DEFAULT_REGION = your_eqs_region ENDPOINT = end_point_url ``` *create a file named* **index.js** ```javascript import { SQSClient } from '@aws-sdk/client-sqs'; import dotenv from 'dotenv'; dotenv.config(); const eqs_client = new SQSClient({ region: process.env.AWS_REGION, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }, endpoint: process.env.ENDPOINT, }); export { eqs_client }; ``` **Methods available for eqs_client** ## Change VisibilityTimeout **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const queueUrl = 'YOUR_QUEUE_URL'; const receiptHandle = 'YOUR_RECEIPT_HANDLE'; const visibilityTimeout = 123; const params = { QueueUrl: queueUrl, ReceiptHandle: receiptHandle, VisibilityTimeout: visibilityTimeout }; eqs_client.changeMessageVisibility(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } }); ``` **Parameters** **QueueUrl** (string)- [Required] The URL of the E2E EQS queue whose message's visibility is changed. **ReceiptHandle** (string) - [Required] The receipt handle is associated with the message whose visibility timeout is changed. This parameter is returned by the *ReceiveMessage* action **VisibilityTimeout** (integer) - [Required] The new value for the message's visibility timeout (in seconds) **Response Syntax** ```javascript None ``` ## Change VisibilityTimeout batch **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const queueUrl = 'YOUR_QUEUE_URL'; const entries = [ { Id: 'MESSAGE_ID_1', ReceiptHandle: 'RECEIPT_HANDLE_1', VisibilityTimeout: 123 }, { Id: 'MESSAGE_ID_2', ReceiptHandle: 'RECEIPT_HANDLE_2', VisibilityTimeout: 456 } ]; const params = { QueueUrl: queueUrl, Entries: entries }; eqs_client.changeMessageVisibilityBatch(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Successful); console.log("Failures", data.Failed); } }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue whose message's visibility is changed. **Entries** (Array) - [Required] (map) *id [Required]-(string) An identifier for this particular receipt handle used to communicate the result* *ReceiptHandle [Required] -(string) A receipt handle* *VisibilityTimeout - (string) The new value (in seconds) for the message’s visibility timeout* **Response Syntax** ```javascript { Successful: [ { Id: 'string' }, ], Failed: [ { Id: 'string', SenderFault: true | false, Code: 'string', Message: 'string' }, ] } ``` ## Close connection **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); eqs_client.close(function(err) { if (err) { console.error('Error closing the connection: ', err); } else { console.log('Connection closed successfully.'); } }); ``` **Response Syntax** ```javascript None ``` ## Create Queue **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const params = { QueueName: 'QUEUE_NAME', Attributes: { 'DelaySeconds': '0', 'MaximumMessageSize': '262144', 'MessageRetentionPeriod': '345600', 'ReceiveMessageWaitTimeSeconds': '0', 'VisibilityTimeout': '30' }, tags: { 'Tag1': 'Value1', 'Tag2': 'Value2' } }; eqs_client.createQueue(params, function(err, data) { if (err) { console.log('Error creating queue: ', err); } else { console.log('Queue URL: ', data.QueueUrl); } }); ``` **Parameters** **QueueName** (string)- [Required] 1 - A queue name can have up to 80 characters 2 - Valid values: alphanumeric characters, hyphens ( -), and underscores ( _). **Attributes** (map)- Attributes could be 1 - DelaySeconds - Time(second), to which extent delivery of messages is delayed in the queue Valid values - 0 to 900 (second) default - 0 (second) 2 - MaximumMessageSize - The size of the message after which the queue will reject the message Valid values - 1,024 bytes (1 KiB) to 262,144 bytes (256 KiB) default - 262,144 bytes(256 KiB) 3 - MessageRetentionPeriod - Time to which extent a queue will retain a message Valid values - 60 seconds (1 minute) to 1,209,600 seconds (14 days) default - 345,600 (4 days) 4 - ReceiveMessageWaitTimeSeconds - Time to which extent *ReceiveMessage* action waits before receiving a message Valid values - 0 to 20 (seconds) default - 0 (second) 5 - VisibilityTimeout - The amount of time that a message in a queue is invisible to other consumers after a consumer retrieves it. Valid values - 0 to 43,200 seconds (12 hours) default - 30 second **tags** (map) - 1 - Adding more than 50 tags to a queue isn't recommended. 2 - A new tag with a key identical to that of an existing tag overwrites the existing tag. **Response Syntax** ```javascript { QueueUrl: 'string' } ``` ## Delete message **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); eqsClient.deleteMessage({ QueueUrl: 'string', ReceiptHandle: 'string' }, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Message Deleted", data); } }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are deleted. **ReceiptHandle** (string) - [Required] The receipt handle is associated with the message to delete. **Response Syntax** ```javascript None ``` ## Delete message in batch **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const params = { QueueUrl: 'STRING_VALUE', Entries: [ { Id: 'STRING_VALUE', ReceiptHandle: 'STRING_VALUE' }, ], }; sqs.deleteMessageBatch(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are deleted. **Entries** (Array) - [Required] (map) *id [Required]-(string) An identifier for this particular receipt handle used to communicate the result* *ReceiptHandle [Required] -(string) A receipt handle* **Response Syntax** ```javascript { "Successful": [ { "Id": "string" } ], "Failed": [ { "Id": "string", "SenderFault": true|false, "Code": "string", "Message": "string" } ] } ``` ## Delete queue **Request Syntax** ```javascript var params = { QueueUrl: 'STRING_VALUE' /* required */ }; eqs_client.deleteQueue(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to delete. **Response Syntax** ```javascript None ``` ## Get Queue Attributes **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const params = { QueueUrl: 'QUEUE_URL', AttributeNames: [ 'All' ] }; eqs_client.getQueueAttributes(params, (err, data) => { if (err) { console.log('Error', err); } else { console.log('Success', data.Attributes); } }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which attributes are get. **AttributeNames** (Array) - [Optional] A list of attributes for which to retrieve information *All - it specifies, returns all values* you can also specify specific attributes in the list *As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']* **Response Syntax** ```javascript { Attributes: { string: string } } ``` ## Get queue url **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueName: 'STRING_VALUE' }; eqs_client.getQueueUrl(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueName** (string) -[Required] The name of the queue whose URL must be fetched. **Response Syntax** ```javascript { QueueUrl: 'STRING_VALUE' } ``` ## List queue tags **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: 'STRING_VALUE' }; eqs_client.listQueueTags(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue of which all the tags must be listed. **Response Syntax** ```javascript { Tags: { 'STRING_VALUE': 'STRING_VALUE', } } ``` ## List queues **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueNamePrefix: 'STRING_VALUE', MaxResults: 123 }; sqs.listQueues(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueNamePrefix** (string) - [Optional] A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned. **MaxResults** (integer) - [Optional] The maximum number of results to include in the response. Valid values - 1 to 1000 **Response Syntax** ```javascript { QueueUrls: [ 'STRING_VALUE', ] } ``` ## Receive message **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: 'STRING_VALUE', AttributeNames: [ 'All', ], MessageAttributeNames: [ 'STRING_VALUE', ], MaxNumberOfMessages: 2, VisibilityTimeout: 25, WaitTimeSeconds: 10, ReceiveRequestAttemptId: 'STRING_VALUE' }; eqs_client.receiveMessage(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are received. **AttributeNames** (Array) - A list of attributes that need to be returned along with each message. *All - it specifies, returns all values* you can also specify specific attributes in the list *As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']* **MessageAttributeNames** (Array) - The name of the message attribute. **MaxNumberOfMessages** (integer) - The maximum number of messages to return. Valid range - 1 to 10 default - 1 **VisibilityTimeout** (integer) - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. **WaitTimeSeconds** (integer) - The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. **Response Syntax** ```javascript { Messages: [ { MessageId: 'STRING_VALUE', ReceiptHandle: 'STRING_VALUE', MD5OfBody: 'STRING_VALUE', Body: 'STRING_VALUE', Attributes: { 'STRING_VALUE': 'STRING_VALUE' }, MD5OfMessageAttributes: 'STRING_VALUE', MessageAttributes: { 'STRING_VALUE': { StringValue: 'STRING_VALUE', BinaryValue: 'BYTES_VALUE', DataType: 'STRING_VALUE' } } } ] } ``` ## Send message **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: 'STRING_VALUE', /* required */ MessageBody: 'STRING_VALUE', DelaySeconds: 0, MessageAttributes: { 'STRING_VALUE': { DataType: 'STRING_VALUE', BinaryValue: Buffer.from('...') || 'STRING_VALUE', StringValue: 'STRING_VALUE' }, }, MessageSystemAttributes: { 'STRING_VALUE': { DataType: 'STRING_VALUE', BinaryValue: Buffer.from('...') || 'STRING_VALUE', StringValue: 'STRING_VALUE' }, } }; eqs_client.sendMessage(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to which messages are send. **MessageBody** (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB. **DelaySeconds** (integer) - The length of time, in seconds, for which to delay a specific message. **MessageAttributes** (map) - Each message attribute consists of a Name, Type, and Value . Name, type, value and the message body must not be empty or null . (string) - name of the message attributes (map) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - [Required] Type of message attributes EQS support the following data type Binary, Number, String **MessageSystemAttributes** (dictionary) - Each message system attribute consists of a Name, Type, and Value. The name, type, value and message body must not be empty or null. (string) - the name of the message attributes (dictionary) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - Type of message attributes EQS support the following data type Binary , Number , String **Response Syntax** ```javascript { 'MD5OfMessageBody': 'string', 'MD5OfMessageAttributes': 'string', 'MD5OfMessageSystemAttributes': 'string', 'MessageId': 'string', 'SequenceNumber': 'string' } ``` ## Send message in batch **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: "STRING_VALUE", // the URL of the E2E EQS queue Entries: [ { Id: "MESSAGE_ID", // an identifier for the message in the batch MessageBody: "MESSAGE_BODY", // the message to send DelaySeconds: 0, // the number of seconds to delay the message (optional) MessageAttributes: { "ATTRIBUTE_NAME": { DataType: "STRING_VALUE", StringValue: "STRING_VALUE", BinaryValue: new Buffer("BYTES_VALUE") } }, MessageSystemAttributes: { "ATTRIBUTE_NAME": { DataType: "STRING_VALUE", StringValue: "STRING_VALUE", BinaryValue: new Buffer("BYTES_VALUE") } } } ] }; eqs_client.sendMessageBatch(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to which messages are sent. **Entries** (Array) - [Required] A list of SendMessageBatchRequestEntry items. (map) - Contains the details of a single E2E EQS message along with an Id. **Id** (string) - [REQUIRED] An identifier for a message in this batch is used to communicate the result. **MessageBody** (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB. **DelaySeconds** (integer) - The length of time, in seconds, for which to delay a specific message. **MessageAttributes** (map) - Each message attribute consists of a Name, Type, and Value. The Name, type, value and message body must not be empty or null. (string) - The name of the message attributes (map) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) -[Required] Type of message attributes EQS support the following data type Binary, Number, String **MessageSystemAttributes** (map) - Each message system attribute consists of a Name, Type, and Value. Name, type, value and the message body must not be empty or null. (string) - The name of the message attributes (map) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - Type of message attributes EQS support following data type Binary , Number , String ``` **Response Syntax** ```javascript { "Successful": [ { "Id": "MESSAGE_ID", "MessageId": "MESSAGE_ID", "MD5OfMessageBody": "MD5_HASH", "MD5OfMessageAttributes": "MD5_HASH", "MD5OfMessageSystemAttributes": "MD5_HASH", "SequenceNumber": "SEQUENCE_NUMBER" } ], "Failed": [] } ``` ## Set queue Attributes **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: 'STRING_VALUE', /* required */ Attributes: { 'AttributeName1': 'AttributeValue1', 'AttributeName2': 'AttributeValue2', } }; eqs_client.setQueueAttributes(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue of which attributes should be set. **Attributes** (map) : [Required] A map of attributes to set. **Response Syntax** ```javascript None ``` ## Tag queue **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); const params = { QueueUrl: 'YOUR_QUEUE_URL', Tags: { 'YOUR_TAG_KEY': 'YOUR_TAG_VALUE', } }; eqs_client.tagQueue(params, (err, data) => { if (err) { console.log('Error', err); } else { console.log('Queue tagged successfully'); } }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue. **Tags** (map) - [Required] The list of tags to be added to the specified queue. **Response Syntax** ```javascript None ``` ## Untag queue **Request Syntax** ```javascript import { SQS } from 'aws-sdk'; const eqs_client = new SQS(); var params = { QueueUrl: 'STRING_VALUE', /* required */ TagKeys: [ 'STRING_VALUE', ] }; eqsClient.untagQueue(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); }); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue. **TagKeys** (list) - [Required] The list of tags to be removed from the specified queue. **Response Syntax** ```javascript None ``` ---