MCPcopy Index your code
hub / github.com/ballerina-platform/module-ballerinax-aws.sqs

github.com/ballerina-platform/module-ballerinax-aws.sqs @v4.1.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.3 ↗ · + Follow
137 symbols 298 edges 29 files 32 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Ballerina AWS SQS Library

Build codecov Trivy GraalVM Check GitHub Last Commit

Overview

Amazon Simple Queue Service (SQS) is a fully managed message queuing service provided by Amazon Web Services (AWS) that enables you to decouple and scale microservices, distributed systems, and serverless applications.

The ballerinax/aws.sqs package allows developers to interact with Amazon SQS seamlessly using Ballerina. This connector provides capabilities to send, receive, delete messages, and manage SQS queues programmatically.

Setup guide

Login to AWS Console

Log into the AWS Management Console. If you don’t have an AWS account yet, you can create one by visiting the AWS sign-up page. Sign up is free, and you can explore many services under the Free Tier.

Create a user

  1. In the AWS Management Console, search for IAM in the services search bar.
  2. Click on IAM

create-user-1.png

  1. Click Users

create-user-2.png

  1. Click Create User

create-user-3.png

  1. Provide a suitable name for the user and continue

specify-user-details.png

  1. Add necessary permissions by adding the user to a user group, copy permissions or directly attach the policies. And click next.

set-user-permissions.png 7. Review and create the user

review-create-user.png

Get user access keys

  1. Click the user that created

users.png

  1. Click Create access key

create-access-key-1.png

  1. Click your use case and click next.

select-usecase.png

  1. Record the Access Key and Secret access key. These credentials will be used to authenticate your Ballerina application with Amazon SQS.

retrieve-access-key.png

Quickstart

To use the aws.sqs connector in your Ballerina project, modify the .bal file as follows.

Step 1: Import the module

import ballerinax/aws.sqs;

Step 2: Instantiate a new connector

Create a new sqs:Client by providing the region and authentication configurations.

configurable string accessKeyId = ?;
configurable string secretAccessKey = ?;

sqs:Client sqsClient = check new ({
   region: sqs:US_EAST_1,
   auth: {
      accessKeyId,
      secretAccessKey
   }
});

Alternative authentication methods

Profile-based authentication

You can use AWS profile-based authentication as an alternative to static credentials.

sqs:Client sqsClient = check new ({
   region: sqs:US_EAST_1,
   auth: {
      profileName: "myAwsProfile",
      credentialsFilePath: "/path/to/custom/credentials"
   }
});

Note: Ensure your AWS credentials file follows the standard format.

```ini [default] aws_access_key_id = YOUR_ACCESS_KEY_ID aws_secret_access_key = YOUR_SECRET_ACCESS_KEY

[myAwsProfile] aws_access_key_id = ANOTHER_ACCESS_KEY_ID aws_secret_access_key = ANOTHER_SECRET_ACCESS_KEY ```

Step 3: Invoke the connector operations

Now, utilize the available connector operations.

Create a queue

string queueUrl = check sqsClient->createQueue("my-test-queue");

Send a message

sqs:SendMessageResponse response = check sqsClient->sendMessage(queueUrl, "Hello from Ballerina!");

Receive messages

sqs:Message[] messages = check sqsClient->receiveMessage(queueUrl);

Delete a message

check sqsClient->deleteMessage(queueUrl, receiptHandle);

Batch operations

// Send multiple messages at once
sqs:SendMessageBatchEntry[] entries = [
    {id: "msg1", body: "First message"},
    {id: "msg2", body: "Second message", delaySeconds: 5}
];
sqs:SendMessageBatchResponse batchResponse = check sqsClient->sendMessageBatch(queueUrl, entries);

// Delete multiple messages at once
sqs:DeleteMessageBatchEntry[] deleteEntries = [
    {id: "del1", receiptHandle: "receipt-handle-1"},
    {id: "del2", receiptHandle: "receipt-handle-2"}
];
sqs:DeleteMessageBatchResponse deleteResponse = check sqsClient->deleteMessageBatch(queueUrl, deleteEntries);

Queue management

// List all queues
sqs:ListQueuesResponse queues = check sqsClient->listQueues();

// Get queue attributes
sqs:GetQueueAttributesResponse attributes = check sqsClient->getQueueAttributes(queueUrl);

// Set queue attributes
sqs:QueueAttributes newAttributes = {
    visibilityTimeout: 300,
    messageRetentionPeriod: 1209600 // 14 days
};
check sqsClient->setQueueAttributes(queueUrl, newAttributes);

// Delete a queue
check sqsClient->deleteQueue(queueUrl);

Working with FIFO queues

For First-In-First-Out (FIFO) queues, you need to provide additional parameters:

// Create a FIFO queue
sqs:QueueAttributes fifoAttributes = {
    fifoQueue: true,
    contentBasedDeduplication: true
};
string fifoQueueUrl = check sqsClient->createQueue("my-fifo-queue.fifo", queueAttributes = fifoAttributes);

// Send message to FIFO queue
sqs:SendMessageResponse fifoResponse = check sqsClient->sendMessage(
    fifoQueueUrl,
    "FIFO message",
    messageGroupId = "group1",
    messageDeduplicationId = "unique-id-1"
);

Step 4: Run the Ballerina application

Use the following command to compile and run the Ballerina program.

bal run

Examples

The ballerinax/aws.sqs connector provides practical examples illustrating usage in various scenarios. Explore these examples:

  1. Basic Queue Consumer – Demonstrates creating a standard SQS queue, sending messages, and consuming them using a Ballerina listener.
  2. Basic Queue Operations – Shows how to create a queue, send, receive, and delete messages, and delete the queue.
  3. Advanced Messaging Features – Demonstrates advanced messaging features such as message attributes, batch sending, and custom queue attributes.
  4. FIFO Queue – Shows how to work with FIFO queues, including sending messages with different messageGroupIds and grouping received messages.

Build from the source

Prerequisites

  1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:

  2. Oracle JDK

  3. OpenJDK

Note: After installation, remember to set the JAVA_HOME environment variable to the directory where JDK was installed.

  1. Download and install Ballerina Swan Lake.

  2. Download and install Docker.

Build options

Execute the commands below to build from the source.

  1. To build the package:

bash ./gradlew clean build

  1. To run the tests:

bash ./gradlew clean test

  1. To build the without the tests:

bash ./gradlew clean build -x test

  1. To debug package with a remote debugger:

bash ./gradlew clean build -Pdebug=<port>

  1. To debug with the Ballerina language:

bash ./gradlew clean build -PbalJavaDebug=<port>

  1. Publish the generated artifacts to the local Ballerina Central repository:

bash ./gradlew clean build -PpublishToLocalCentral=true

  1. Publish the generated artifacts to the Ballerina Central repository:

bash ./gradlew clean build -PpublishToCentral=true

Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All the contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

Core symbols most depended-on inside this repo

Shape

Method 109
Class 28

Languages

Java100%

Modules by API surface

native/src/main/java/io/ballerina/lib/aws/sqs/client/NativeClientAdaptor.java24 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/listener/Service.java13 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/listener/Listener.java11 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/listener/MessageReceiver.java9 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/ReceiveMessageMapper.java5 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/listener/MessageDispatcher.java5 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/ModuleUtils.java5 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/StartMessageMoveTaskMapper.java4 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/SendMessageMapper.java4 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/SendMessageBatchMapper.java4 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/ListQueuesMapper.java4 symbols
native/src/main/java/io/ballerina/lib/aws/sqs/mappers/GetQueueAttributesMapper.java4 symbols

For agents

$ claude mcp add module-ballerinax-aws.sqs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page