SXAPI Resource : AWS SQS
This resource allow you to interact with the AWS SQS Webservice. Programmers can access resource methods and embed this module methods into there own method and endpoints. API developpers can use resource endpoints into there configuration profile to expose AWS SQS data.
This resource is based on aws-sdk npm module and is part of the sxapi-core engine from .
Resource configuration
To configure this resource, you must add a config key under the resources
section of your configuration profile.
This key must be a unique string and will be considered as the resource id. The value
must be an object who must have the appropriate configuration parameters.
For a better understanting of the sxapi configuration profile, please refer to the configuration guide
This config object will be passed to require('aws-sdk').SQS()
method of the nodejs aws-sdk module.
Read aws-sdk SQS documentation
for a complete list of the parameters that you can use in this config object.
Resource config parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
_class | yes | string | module name. Must be aws_sqs for this resource | |
ACCESS_ID | yes | string | your AWS access key ID. | |
ACCESS_KEY | yes | string | your AWS secret access key. | |
SESSION_TOKEN | no | string | the optional AWS session token to sign requests with. | |
QueueUrl | no | string | the default queue url used by this resource | |
region | no | string | us-west-1 | the region to send service requests to. See AWS.SQS.region for more information. |
... | no | N/A | any SQS option. See see aws-sdk SQS documentation. |
Example
This is a sample configuration of this resource. You must add this section under
the resources
section of your configuration profile
resources:
aws-sqs-id:
_class: aws_sqs
ACCESS_ID: XXXXXXXXXXXXX
ACCESS_KEY: XXXXXXXXXXXXX
region: eu-west-3
QueueUrl: https://sqs.eu-west-3.amazonaws.com
Resource methods
If you want to use this resource in our own module, you can retrieve this resource
instance by using $app.resources.get('aws-sqs-id')
where aws-sqs-id
is the
id of your resource as defined in the resource configuration.
This module come with several methods for manipulating aws SQS resources.
1. read method
2. removeMessage method
3. sendMessage method
4. listQueues method
5. createQueue method
6. deleteQueue method
Method read
get a list of message for a list queue.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
options | no | object | Configuration option passed to the AWS SQS.receiveMessage method. Read documentation for more options | |
options.QueueUrl | no | string | the queue url to read message from. If not defined will use the default resource queueUrl | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | a list of messages from the queue |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.read(
{QueueUrl:"https://sqs.eu-west-3.amazonaws.com"},
function (error, response) {
console.log(error, response);
});
Method removeMessage
Remove a message from a list queue.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
options | yes | object | Configuration option passed to the AWS SQS.deleteMessage method. Read documentation for more options | |
options.ReceiptHandle | yes | string | the message Id to remove | |
options.QueueUrl | no | string | the queue url to delete message from. If not defined will use the default resource queueUrl | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | meta informations about the result of this deletion |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.removeMessage(
{ReceiptHandle:"df654s8#9d23s43f3mgh?66se63"},
function (error, response) {
console.log(error, response);
});
Method sendMessage
Send a message to the given queue.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
message | yes | object | The message object | |
options | yes | object | Configuration option passed to the AWS SQS.sendMessage method. Read documentation for more options | |
options.QueueUrl | no | string | the queue url where message should be inserted. If not defined will use the default resource queueUrl | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | meta informations about the result of this insertion |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.sendMessage(
{ id : "msg1", "key" : "value" },
{ QueueUrl:"https://sqs.eu-west-3.amazonaws.com" },
function (error, response) {
console.log(error, response);
});
Method listQueues
get a list of all queues availables.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
options | no | object | Configuration option passed to the AWS SQS.listQueues method. Read documentation for more options | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | a list of messages from the queue |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.listQueues({}, function (error, response) {
console.log(error, response);
});
Method createQueue
Create a new message queue
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
options | yes | object | Configuration option passed to the AWS SQS.createQueue method. Read documentation for more options | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | meta informations about the result of this insertion |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.createQueue({ }, function (error, response) {
console.log(error, response);
});
Method deleteQueue
Delete a message queue.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
options | yes | object | Configuration option passed to the AWS SQS.deleteQueue method. Read documentation for more options | |
callback | no | function | default | callback function called when server answer the request. If not defined, dropped to a default function who output information to the debug console |
callback(error,response) | N/A | mixed | null | will be false or null if no error returned from the AWS SQS Webservice. Will be a string message describing a problem if an error occur. |
callback(error,response) | N/A | mixed | meta informations about the result of this insertion |
Example
var resource = $app.resources.get('aws-sqs-id');
resource.deleteQueue({ }, function (error, response) {
console.log(error, response);
});
Resource endpoints
This module come with 4 endpoints who can interact with any aws_sqs method.
1. listMessages endpoint
2. addMessage endpoint
3. deleteMessage endpoint
4. listQueue endpoint
5. addQueue endpoint
6. deleteQueue endpoint
listMessages endpoint
The purpose of this endpoint is to make call to a AWS SQS Webservice and to return the a list of message from a given queue.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "get" | |
config | no | string | Configuration object to pass to the read resource method (see options) |
Example
server:
endpoints:
- path: "/aws_sqs"
resource: aws-sqs-id
endpoint: listMessages
config:
QueueUrl: https://sqs.eu-west-3.amazonaws.com
addMessage endpoint
The purpose of this endpoint is to insert a key into a AWS SQS Webservice. Document will be the HTTP body of the query.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "create" | |
config | no | string | Configuration object to pass to the sendMessage resource method (see options) |
Example
server:
endpoints:
- path: "/aws_sqs/:id"
method: POST
resource: aws-sqs-id
endpoint: addMessage
deleteMessage endpoint
The purpose of this endpoint is to delete a message from AWS SQS queue. Id is defined by the context.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "delete" | |
config | no | object | Configuration option passed to the AWS SQS.deleteMessage method. Read documentation for more options |
Example
server:
endpoints:
- path: "/aws_sqs/:id"
method: DELETE
resource: aws-sqs-id
endpoint: deleteMessage
listQueue endpoint
The purpose of this endpoint is to make call to a AWS SQS Webservice and to return the a list of availables queues.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "get" | |
config | no | string | Configuration object to pass to the listQueues resource method (see options) |
Example
server:
endpoints:
- path: "/aws_sqs"
resource: aws-sqs-id
endpoint: listQueue
config:
QueueUrl: https://sqs.eu-west-3.amazonaws.com
addQueue endpoint
The purpose of this endpoint is to insert a key into a AWS SQS Webservice. Id is defined by the context.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "create" | |
config | no | string | Configuration object to pass to the createQueue resource method (see options) |
Example
server:
endpoints:
- path: "/aws_sqs/:id"
method: POST
resource: aws-sqs-id
endpoint: addQueue
deleteQueue endpoint
The purpose of this endpoint is to delete a complete AWS SQS queue. Id is defined by the context.
Parameters
Param | Mandatory | Type | default | Description |
---|---|---|---|---|
path | yes | string | path used as client endpoint (must start with /) | |
resource | yes | string | resource id declared in the resource of your config profile | |
endpoint | yes | string | endpoint name declared in the resource module. In this case must be "delete" | |
config | no | object | Configuration option passed to the AWS SQS.deleteQueue method. Read documentation for more options |
Example
server:
endpoints:
- path: "/aws_sqs/:id"
method: DELETE
resource: aws-sqs-id
endpoint: deleteQueue