Contact Free trial Login

Amazon SNS Connector

Support Category: Select

Amazon SNS Connector v4.3

The Anypoint Connector for Amazon SNS provides connectivity to the Amazon Simple Notification Service (Amazon SNS) API, enabling you to build distributed web-enabled applications. Mule applications can use the Amazon SNS Connector to easily push real-time notification messages to interested subscribers over multiple delivery protocols.

Prerequisites

To use the Amazon SNS Connector, you must have the following:

  • Access to Amazon Web Services - SNS.

  • To access AWS with the connector, you need the credentials in the form of an Amazon IAM.

  • Anypoint Studio version 7.0 (or higher) or the Anypoint Design Center.

Compatibility

Amazon SNS connector is compatible with:

Application/Service Version

Mule Runtime

4.1.x

AWS SDK for Java

1.11.604

Java

1.8.0_x

Anypoint Studio

7.0 or higher

Install the Connector

From Exchange

  1. In Studio, create a Mule Project.

  2. Click the Exchange (X) icon in the upper left of the Studio task bar.

  3. In Exchange, click Login and supply your Anypoint Platform username and password.

  4. In Exchange, search for "SNS".

  5. Select Amazon SNS Connector - Mule 4, and click Add to project.

  6. Follow the prompts to install the connector.

From Within Studio

  1. In Studio, create a Mule Project.

  2. In the Mule Palette, click (X) Search in Exchange.

  3. In Add Modules to Project, type the name of the connector in the search field.

  4. Click the connector name in Available modules.

  5. Click Add >.

  6. Click Finish.

Configure the Connector Global Element

To use the Amazon SNS connector in your Mule application, configure a global Amazon SNS element that can be used by all the Amazon SNS connectors in the application.

Configure with Studio Visual Editor

  1. Click the Global Elements tab at the base of the canvas.

  2. In the Global Configuration Elements screen, click Create.

    amazon sns config global wizard
  3. In the Choose Global Type wizard, expand Connector Configuration and select Amazon SNS Configuration and click OK.

    amazon sns global config

    In this image, the placeholder values refer to a configuration file placed in the src folder of your project.

  4. Configure the parameters according to instructions below.

    Parameter Description

    Name

    Enter a name for the configuration to reference it.

    Access Key

    Alphanumeric text string that uniquely identifies the user who owns the account.

    Secret Key

    Key that plays the role of a password.

    Try Default AWS Credentials Provider Chain

    Checkbox that controls whether temporary credentials should be used.

    Region Endpoint

    Set the topic region endpoint.

    Topic Arn

    Topic ARN to test the connectivity.

    You can either enter your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better reusability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ.

  5. Keep the Pooling Profile and the Reconnection tabs with their default entries.

  6. Click Test Connection to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to your instance of Amazon SNS.

  7. Click OK to save the global connector configurations.

Configure with XML Editor or Standalone

  1. Ensure that you have included the Amazon SNS namespaces in your configuration file.

    <?xml version="1.0"?>
    
    <mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
    http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/sns
    http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
    http://www.mulesoft.org/schema/mule/http
    http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    
    <!-- Put your flows and configuration elements here -->
    
    </mule>
  2. Create a global Amazon SNS configuration outside and above your flows, use the following global configuration code.

    <sns:config
      name="Amazon_SNS_configuration"
      doc:name="Amazon SNS configuration">
    <sns:basic-connection
      accessKey="${config.accessKey}"
      secretKey="${config.secretKey}"
      testTopicArn="${sns.topic.arn}" />
    </sns:config>

    If you or your IAM users forget or lose the secret access key, you can create a new access key.

Use This Connector

Amazon SNS connector is an operation-based connector, which means that when you add the connector to your flow, you need to configure a specific operation for the connector to perform. The connector currently supports the following list of operations:

Operation Description

Add Permission

Adds a statement to a topic’s access control policy

Confirm Subscription

The ConfirmSubscription action verifies an endpoint owner’s intent to receive messages by validating the token sent to the endpoint by an earlier Subscribe action.

Create Platform Application

Creates a platform application object for one of the supported push notification services, such as APNS and GCM, to which devices and mobile apps may register.

Create Platform Endpoint

Creates an endpoint for a device and mobile app on one of the supported push notification services.

Create Topic

The CreateTopic action creates a topic to which notifications can be published.

Delete Endpoint

Deletes the endpoint for a device and mobile app from Amazon SNS.

Delete Platform Application

Deletes a platform application object for one of the supported push notification services, such as APNS and GCM.

Delete Topic

The DeleteTopic action deletes a topic and all its subscriptions.

Get Endpoint Attributes

Retrieves the endpoint attributes for a device on one of the supported push notification services, such as GCM and APNS.

Get Platform Application Attributes

Retrieves the attributes of the platform application object for the supported push notification services, such as APNS and GCM.

Get Subscription Attributes

The GetSubscriptionAttributes action returns all of the properties of a subscription.

Get Topic Attributes

The GetTopicAttributes action returns all of the properties of a topic.

List Endpoints By Platform Application

Lists the endpoints and endpoint attributes for devices in a supported push notification service, such as GCM and APNS.

List Platform Applications

Lists the platform application objects for the supported push notification services, such as APNS and GCM.

List Subscriptions By Topic

The SubscriptionsByTopic action returns a list of the subscriptions to a specific topic.

List Subscriptions

The ListSubscriptions action returns a list of the requester’s subscriptions.

List Topics

The ListTopics action returns a list of the requester’s topics.

Publish

The Publish action sends a message to all of a topic’s subscribed endpoints.

Remove Permission

The RemovePermission action removes a statement from a topic’s access control policy.

Set Endpoint Attributes

Sets the attributes for an endpoint for a device on one of the supported push notification services, such as GCM and APNS.

Set Platform Application Attributes

Sets the attributes of the platform application object for the supported push notification services, such as APNS and GCM.

Set Subscription Attributes

The SubscriptionAttributes action allows a subscription owner to set an attribute of the topic to a new value.

Set Topic Attributes

The TopicAttributes action allows a topic owner to set an attribute of the topic to a new value.

Subscribe

The Subscribe action prepares to subscribe an endpoint by sending the endpoint a confirmation message.

Unsubscribe

The Unsubscribe action deletes a subscription.

Connector Namespace and Schema

When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/sns Schema Location: http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd

If you are manually coding the Mule application in Studio’s XML editor or other text editor, paste the namespace and schema into your Configuration XML.

<?xml version="1.0"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sns
http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

<!-- Put your flows and configuration elements here -->

</mule>

Update POM File

To reference the SNS connector from Mule application, include the following XML snippet in your pom.xml file.

<dependency>
    <groupId>com.mulesoft.connectors</groupId>
    <artifactId>mule-amazon-sns-connector</artifactId>
    <version>RELEASE</version>
    <classifier>mule-plugin</classifier>
</dependency>

The Mule runtime engine translates the RELEASE version keyword to the current version.

To specify a version number in the pom.xml file information, access the version of the connector in Anypoint Exchange and click Dependency Snippets.

Use Cases and Demos

Common use cases for the connector:

Use Case Description

Sending Amazon SNS messages to Amazon SQS queues

Amazon SNS works closely with Amazon Simple Queue Service (Amazon SQS). By using Amazon SNS and Amazon SQS together, messages can be delivered to applications that require immediate notification of an event, and also persisted in an Amazon SQS queue for other applications to process at a later time.

Sending Amazon SNS messages to HTTP/HTTPS endpoints

You can use Amazon SNS to send notification messages to one or more HTTP or HTTPS endpoints. When you subscribe an endpoint to a topic, you can publish a notification to the topic and Amazon SNS sends an HTTP POST request delivering the contents of the notification to the subscribed endpoint.

Demo Mule Application Using the Connector

Send messages to Amazon SQS Queue.

When you subscribe an Amazon SQS queue to an Amazon SNS topic, you can publish a message to the topic and Amazon SNS sends an Amazon SQS message to the subscribed queue.

You can subscribe an Amazon SQS queue to an Amazon SNS topic using the AWS Management Console for Amazon SQS, which simplifies the process.

Sending messages to SQS Queue
  1. Create a new Mule Project in Anypoint Studio.

  2. Add these properties to mule-artifact.properties file to hold your Amazon SNS and SQS credentials.

  3. Place the properties file in the project’s src/main/app directory.

    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    sns.topic.arn=<SNS Topic ARN>
  4. Select a region from the drop down. The default region is US_EAST1.

    sqs.accesskey=<Access Key>
    sqs.secretkey=<Secret Key>
    sqs.queueName=<SQS Queue Name>
  5. Select a region from the drop down.

    sqs.queueUrl=<SQS Queue URL>
  6. Drag the HTTP Connector and select the Listener operation to the beginning of the flow and configure the following parameters:

    sns http config props
    Parameter Value

    Display Name

    HTTP

    Extension Configuration

    If no HTTP element has been created yet, click the plus sign to add a new HTTP Listener Configuration and click OK (Fill 0.0.0.0 for Host and 8081 for port).

    Path

    /

  7. Drag the Amazon SNS Connector Publish operation next to the HTTP Listener.

  8. Configure the SNS connector by adding a new Amazon SNS Global Element. Click the plus sign next to the Connector Configuration field.

  9. Configure the global element:

    Parameter Description

    Value

    Name

    Enter a name for the configuration to reference it.

    <Configuration_Name>

    Access Key

    Alphanumeric text string that uniquely identifies the user who owns the account.

    ${config.accesskey}

    Secret Key

    Key that plays the role of a password.

    ${config.secretkey}

    Region Endpoint

    Set the queue reqion

    User can select the Region by using dropdown.

    Topic Arn

    Topic ARN to test the connectivity.

    ${sns.topic.arn}

    Your configuration should look like this:

    amazon sns use case config

    The corresponding XML configuration should be as follows:

    <sns:config name="Amazon_SNS_configuration" doc:name="Amazon SNS configuration">
    <sns:basic-connection
      accessKey="${config.accessKey}"
      secretKey="${config.secretKey}"
      testTopicArn="${sns.topic.arn}" />
    </sns:config>
  10. Click Test Connection to confirm that Mule can connect with the SNS instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.

  11. Back in the properties editor of the Amazon SNS connector, configure the remaining parameters:

    Parameter Value

    Basic Settings

    Display Name

    Publish message to topic (or any other name you prefer).

    Connector Configuration

    Amazon_SNS_Configuration (the reference name to the global element you have created).

    Operation

    Publish

    General

    Define attributes

    Select to define the Publish attributes

    Topic Arn

    ${sns.topic.arn} (or any other topic arn).

    Message

    Hello World!

    Subject

    Testing publish to queue.

    amazon sns publish message to flow
  12. Check that your XML looks like this:

    <sns:publish config-ref="Amazon_SNS_configuration" doc:name="Publish" >
        <sns:publish-details
          message="Hello World!"
          subject="Testing publish to queue"
          topicArn="${sns.topic.arn}"/>
    </sns:publish>
  13. Add a Logger scope after the Amazon SNS connector to print the data that is being processed by the Publish operation in the Studio console.

    Parameter Value

    Display Name

    Logger (or any other name you prefer)

    Message

    Message ID: #[payload]

    Level

    INFO

    amazon sns logger
  14. Drag a Flow scope onto the canvas to add another flow to receive the message published by SNS.

  15. Drag the Amazon SQS Connector > Receive Messages in the left side of the new flow and configure it according to the steps below:

  16. Click the plus sign next to the Connector Configuration field to add a new Amazon SQS global element.

  17. Configure the global element:

    Parameter Description Value

    Name

    Enter a name for the configuration to reference it.

    Configuration name

    Access Key

    Alphanumeric text string that uniquely identifies the user who owns the account.

    ${sqs.accesskey}

    Secret Key

    Key that plays the role of a password.

    ${sqs.secretkey}

    Queue Name

    Set the name of the queue.

    ${sqs.queueName}

    Queue URL

    Set the queue URL

    ${sqs.queueUrl}

    Region Endpoint

    Set the queue reqion

    Select the region from the drop down.

    Your configuration should look like this (Queue URL can be skipped if Queue Name is specified):

    amazon sns sqs config

    The corresponding XML configuration should contain these settings:

    <sqs:config
        name="Amazon_SQS_Configuration"
        accessKey="${sqs.accesskey}"
        secretKey="${sqs.secretkey}"
        doc:name="Amazon SQS: Configuration"
        defaultQueueName="${sqs.queueName}"
        url="${sqs.queueUrl}"/>

    This configures Amazon SNS to send notifications as messages to Amazon SQS.

  18. Click Test Connection to confirm that Mule can connect with the SQS instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.

  19. In the properties editor of the Amazon SQS connector, configure the remaining parameters:

    Parameter Value

    Basic Settings

    Display Name

    Amazon SQS (Streaming) (or any other name you prefer).

    Connector Configuration

    Amazon_SQS_Configuration (the reference name to the global element you have created).

    Other fields in the group General

    Default values

  20. Check that your XML looks like:

    <sqs:receivemessages config-ref="Amazon_SQS_Configuration" doc:name="Receivemessages" doc:id="ID_VALUE" />
  21. Add a Logger scope after the Amazon SQS connector to print the data that is being passed by the Receive operation in the Mule Console. Configure the Logger according to the table below.

    Parameter Value

    Display Name

    Display Message (or any other name you prefer)

    Message

    Received Message : #[payload]

    Level

    INFO

  22. Right-click the project in Package Explorer. Run As > Mule Application.

  23. Open a web browser and check the response by entering the URL http://localhost:8081/. The logger displays the published message ID on the browser and the received message on the Studio console.

Demo Mule Application XML Code

Paste this code into your XML Editor to quickly load the flow for this example use case into your Mule application.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:sqs="http://www.mulesoft.org/schema/mule/sqs"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/json
http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sqs
http://www.mulesoft.org/schema/mule/sqs/current/mule-sqs.xsd
http://www.mulesoft.org/schema/mule/sns
http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:listener-config name="HTTP_Listener_config"
        doc:name="HTTP Listener config" >
    <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <sqs:config name="Amazon_SQS_Configuration"
            doc:name="Amazon SQS Configuration" >
            <sqs:basic-connection
                accessKey="${sqs.accessKey}"
                secretKey="${sqs.secretKey}"
                defaultQueueName="${sqs.queueName}"/>
    </sqs:config>
    	<sns:config name="Amazon_SNS_configuration"
            doc:name="Amazon SNS configuration" >
    		<sns:basic-connection
                accessKey="${config.accesskey}"
                secretKey="${config.secretkey}" />
    	</sns:config>
   <flow name="publish_message_to_topic" >
        <http:listener config-ref="HTTP_Listener_Configuration"
            path="/"
            doc:name="HTTP"/>
        <sns:publish config-ref="Amazon_SNS_Configuration"
            doc:name="Publish message to topic">
          <sns:publish
            topicArn="${sns.topic.arn}"
            message="Hello world!"
            subject="Testing publish to queue"/>
          </sns:publish>
          <logger message="#[payload]" level="INFO" doc:name="Logger" />
   </flow>
   <flow name="receive_message_from_queue">
        <sqs:receivemessages
            config-ref="Amazon_SQS_Configuration"
            doc:name="Receivemessages" />
   		<logger level="INFO" doc:name="Logger"
        message="#[payload]"/>
   </flow>
</mule>

See Also

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.