Ballerina connector for Amazon SQS connects the Amazon SQS API via Ballerina language with ease. It provides capability to perform operations related to queues and messages.

This module supports Amazon SQS API version 2012-11-05.


Before using this connector in your Ballerina application, complete the following:

  • Create an AWS account
  • Obtain tokens - Follow this link to obtain Access key ID, Secret access key, Region and Account number from navigation pane Users and selecting Security credentials tab.


To use the Amazon SQS connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/aws.sqs module into the Ballerina project as follows.

import ballerinax/aws.sqs;

Step 2: Create a new connector instance

You can now enter the credentials in the SQS client configuration and create the SQS client by passing the configuration as follows.

sqs:ConnectionConfig configuration = {
    accessKey: "<ACCESS_KEY_ID>",
    secretKey: "<SECRET_ACCESS_KEY>",
    region: "<REGION>"

sqs:Client sqsClient = check new (configuration);

Step 3: Invoke connector operation

  1. You can create a queue in SQS as follows with createQueue method for a preferred queue name and the required set of attributes.

    QueueAttributes queueAttributes = {  
        visibilityTimeout : 400,
        fifoQueue : true
    CreateQueueResponse|error response = sqsClient->createQueue("demo.fifo", queueAttributes);
    if (response is CreateQueueResponse) {
        string queueResponse = response.createQueueResult.queueUrl;
        log:printInfo("Created queue URL: " + queueResponse);
  2. Use bal run command to compile and run the Ballerina program.

You can find more samples here

Other versions

See more...