The Ballerina AWS SNS provides the capability to manage topics and subscriptions in AWS SNS.

This module supports Amazon SNS REST API 2010-03-31 version.


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

  1. Create an AWS account
  2. Obtain tokens


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

Step 1: Import connector

Import the ballerinax/aws.sns module into the Ballerina project.

import ballerinax/aws.sns;

Step 2: Create a new connector instance

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

sns:AwsCredentials longTermCredentials = {
    accessKeyId: "<ACCESS_KEY_ID>",
    secretAccessKey: "<SECRET_ACCESS_KEY>"

sns:ConnectionConfig config = {
    region: "<REGION>"

sns:Client snsClient = check new (config);

Step 3: Invoke connector operation

  1. You can create a topic in SNS as follows with createTopic method for a preferred topic name and the required set of attributes.

    sns:TopicAttribute attributes = {
        displayName : "Test"
    sns:CreateTopicResponse response = check amazonSNSClient->createTopic("testTopic", attributes);
    log:printInfo("Created topic: " + response.toString());
  2. Use bal run command to compile and run the Ballerina program.

You can find more samples here

Other versions