---
schema_version: "1"
id: 1d374a20ee0ead0c8ba98f2ed10080a1fadcd799fa5190746386e44bf681ef13
title: Amazon SNS 4.7 Connector Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/amazon-sns-connector/4.7/amazon-sns-connector-examples.md
canonical_url: https://docs.mulesoft.com/amazon-sns-connector/4.7/amazon-sns-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ed1a42960fa65865a5d76f760d4ade3d2840a8a10e5fbd973ab098c8efe244ec
description: MuleSoft Documentation Site
release: "4.7"
latest: false
---
---
product: Amazon SNS Connector
version: 4.7
---

# Amazon SNS 4.7 Connector Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Common use cases for the connector include:

- Sending SNS messages to Amazon SQS queues

- Sending Amazon SNS messages to HTTP/HTTPS endpoints

## Send 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.

- Are persisted in an Amazon SQS queue for other applications to process later.

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

Use AWS Management Console to simplify the process of subscribing an Amazon SQS queue to an Amazon
SNS topic.

## Send 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 am Amazon SNS topic, you can publish a notification to the topic.
Amazon SNS then sends an HTTP POST request that delivers the contents of the notification to the
subscribed endpoint.

## Example: Use the Connector to Send SNS Messages to Amazon SQS Queues

The following diagram shows an example flow for this use case:

![Send messages to SQS](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-use-case-flow.png)

Before you try the example, access Anypoint Studio, and verify that the Mule Palette displays
entries for **Amazon SNS** and **Amazon SQS**. If not, follow the instructions in
[Install the Connector in Studio Using Exchange](https://docs.mulesoft.com/amazon-sns-connector/4.7/amazon-sns-connector-studio#install-connector) to
install both connectors.

To configure a Mule app that uses a connector to send Amazon SNS messages to Amazon SQS queues:

1.  Create a new Mule project in Anypoint Studio.

2.  In the Mule Palette, search for **HTTP**, and select the **Listener** operation:

    ![Select listener](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-select-listener.png)

3.  Drag the **Listener** operation to the canvas.

4.  In the **Listener** configuration, click **+** next to the **Connector configuration** field to
    add a global element.

5.  Accept the defaults.

6.  In the **Listener** configuration **General** tab, set the **Display Name** field to `HTTP` and
    the **Path** field to\`/''.

    ![HTTP properties](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-http-properties.png)

7.  In the Mule Palette, search for **SNS** and select the **Publish** operation:

    ![Publish selection](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-publish-selection.png)

8.  Drag the **Publish** operation to the right of the **HTTP Listener** component.

9.  In the **Publish** configuration, click **+** next to the **Connector configuration** field to
    add a global element.

10. Configure the global element as follows:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Name</strong></p></td><td><p>Name used to reference the configuration</p></td><td><p><code>Amazon_SNS_Configuration</code> or another name</p></td></tr><tr><td><p><strong>Access Key</strong></p></td><td><p>Alphanumeric text string that uniquely identifies the user who owns the account.</p></td><td><p>AWS Access Key</p></td></tr><tr><td><p><strong>Secret Key</strong></p></td><td><p>Key that plays the role of a password</p></td><td><p>AWS secret key</p></td></tr><tr><td><p><strong>Region Endpoint</strong></p></td><td><p>Queue region.</p></td><td><p>The queue region</p></td></tr></tbody></table>

    The following image shows a sample global element for the Publish operation:

    ![SNS global configuration](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-global-config.png)

11. Select the **Configuration XML** tab to view the corresponding XML:

    ```xml
    <sns:config name="Amazon_SNS_Configuration"
      doc:name="Amazon SNS configuration" >
      <sns:basic-connection
        accessKey="EXAMPLEACCESSKEY"
        secretKey="EXAMPLESECRETKEY" />
    </sns:config>
    ```

12. Select the **Global Elements** tab.

13. Select the **Amazon SNS configuration (Configuration)** and click **Edit**.

14. Click **Test Connection** to confirm that Mule can connect with the SNS instance.

    - If the connection is successful, click **OK** to save the configuration.

    - Otherwise, review or correct any incorrect parameters, and test again.

15. Go back to the flow and select **Publish**.

16. Configure parameters in General Tab:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Value</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Display Name</strong></p></td><td><p><code>Publish</code></p></td><td><p>Name of the publish operation.</p></td></tr><tr><td colspan="3"><p><strong>Basic Settings section</strong></p></td></tr><tr><td><p><strong>Connector configuration</strong></p></td><td><p><code>Amazon_SNS_configuration</code></p></td><td><p>The reference name to the global element you created.</p></td></tr><tr><td colspan="3"><p><strong>Target Platform section</strong></p></td></tr><tr><td><p><strong>Topic arn</strong></p></td><td><p><code>arn:aws:sns:us-east-1:123456789012:TopicName</code></p></td><td><p>Amazon Resource Name (ARN) of the topic you want to publish to.</p></td></tr><tr><td><p><strong>Target arn</strong></p></td><td></td><td><p>Amazon Resource Name (ARN) of the platform endpoint you want to publish to.</p></td></tr><tr><td><p><strong>Phone number</strong></p></td><td></td><td><p>The phone number of the device you want to publish to.</p></td></tr><tr><td colspan="3"><p><strong>Message Parameters</strong></p></td></tr><tr><td><p><strong>Message</strong></p></td><td><p><code>`Hello World!`</code></p></td><td><p>Message Body</p></td></tr></tbody></table>

    The following image shows a sample configuration for the Publish Message operation (General
    Tab):

    ![SNS publish message props](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-publish-message-general.png)

17. Configure parameters in Advanced Tab:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Value</th><th>Description</th></tr></thead><tbody><tr><td colspan="3"><p><strong>Message Parameters</strong></p></td></tr><tr><td><p><strong>Subject</strong></p></td><td><p><code>Testing publish to queue</code></p></td><td><p>Subject line when the message is delivered to email endpoints.</p></td></tr><tr><td><p><strong>Message structure</strong></p></td><td><p><code>JSON</code></p></td><td><p>Message structure that will be different for each protocol.</p></td></tr><tr><td><p><strong>Message attributes</strong></p></td><td></td><td><p>Amazon SNS message attributes, as described in the <a href="https://docs.aws.amazon.com/sns/latest/dg/welcome.html">Amazon Simple Notification Service Developer Guide</a>.</p></td></tr><tr><td colspan="3"><p><strong>FIFO Parameters</strong></p></td></tr><tr><td><p><strong>Message Group ID</strong></p></td><td></td><td><p>Token that specifies that a message belongs to a specific message group. Required when publishing to a FIFO topic.</p></td></tr><tr><td><p><strong>Message Deduplication ID</strong></p></td><td></td><td><p>Token used for the deduplication of messages when publishing to a FIFO topic. Allows you to overwrite the value generated by Amazon SNS. Required when content-based deduplication is disabled.</p></td></tr></tbody></table>

    The following image shows a sample configuration for the Publish Message operation (Advanced
    Tab):

    ![SNS publish message props](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-publish-message-advanced.png)

18. Select the **Configuration XML** tab to view the corresponding XML:

    ```xml
    <sns:publish doc:name="Publish" doc:id="276aca8a-334a-4a04-a2ec-8ca4b21743c5"
        config-ref="Amazon_SNS_SNS_configuration"
        topicArn="arn:aws:sns:us-east-1:123456789012:TopicName"
        subject="Testing publish to queue"
        messageStructure="JSON">
        <sns:message ><![CDATA[#['{"default": "Hello world!"}']]]></sns:message>
    </sns:publish>
    ```

    The `default` JSON key has a special meaning for SNS. The key’s value is sent as a message to
    every subscriber, regardless of the protocol used. You must specify this key for the Publish
    Message operation. You can optionally specify other top-level keys that define the message to
    send to a specific transport protocol, such as HTTP or SQS. For more information, see
    [Publish](https://docs.aws.amazon.com/sns/latest/api/API_Publish.html#API_Publish_RequestParameters)
    in the Amazon Simple Notification Service documentation.

### Display the Data Processed by the Publish Operation

Using the same example, add a Logger component to display the data processed by the Publish
operation on the Mule console.

1.  In the Mule Palette, search for the **Logger** component and drag it to the right of the Amazon
    SNS Connector (**Publish**).

2.  Configure the **Logger** component as follows:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Parameter</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Display Name</strong></p></td><td><p><code>Logger</code> or another name</p></td></tr><tr><td><p><strong>Message</strong></p></td><td><p><code>Message: #[payload]</code></p></td></tr><tr><td><p><strong>Level</strong></p></td><td><p><code>INFO</code></p></td></tr></tbody></table>

    ![SNS logger](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-logger.png)

### Receive SNS Messages

Using the same example, add a second flow that enables Amazon SQS to receive messages published by
Amazon SNS:

1.  In the Mule Palette, search for **Flow** and drag the **Flow** component to the canvas.

2.  In the Mule Palette, search for **SQS**, select the **Receive messages** operation, and drag it
    to the left of the **Flow** component.

3.  Select the new component.

4.  Click **+** next to the **Connector configuration** field to add a new Amazon SQS Connector
    global element.

5.  Configure the global element as follows:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th><th>Value</th></tr></thead><tbody><tr><td><p>Name</p></td><td><p>A name by which to refer to the configuration</p></td><td><p><code>Amazon_SQS_Configuration</code> or another name</p></td></tr><tr><td><p>Access Key</p></td><td><p>Alphanumeric text string that uniquely identifies the user who owns the account</p></td><td><p>AWS access key</p></td></tr><tr><td><p>Secret Key</p></td><td><p>Key that plays the role of a password.</p></td><td><p>AWS secret key</p></td></tr><tr><td><p>Region Endpoint</p></td><td><p>Queue region.</p></td><td><p>The queue region</p></td></tr><tr><td><p>Test Queue ARN</p></td><td><p>Queue ARN which will be used in the next step to test the connection</p></td><td><p>Test queue ARN in the following format - <code>arn:aws:sqs:region:account-id:queue-name</code></p></td></tr></tbody></table>

    The following image shows a sample global element for the Receive messages operation:

    ![SNS SQS config](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-sqs-global-config.png)

6.  Select the **Configuration XML** tab to view the corresponding XML:

    ```xml
    <sqs:config name="Amazon_SQS_Configuration"
      doc:name="Amazon SQS Configuration" >
    	<sqs:basic-connection
      region="us_east_1"
      accessKey="EXAMPLEACCESSKEY"
      secretKey="EXAMPLESECRETKEY"
      testQueueArn="arn:aws:sqs:us-east-1:123456789012:QueueName"/>
    </sqs:config>
    ```

7.  Click **Test Connection** to confirm that Mule can connect with the SQS instance:

    - If the connection is successful, click **OK** to save it.

    - If the connection is not successful, review or correct any incorrect parameters, and then test
      again.

8.  In the properties editor of Amazon SQS Connector, configure the remaining parameters:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Parameter</th><th>Value</th></tr></thead><tbody><tr><td colspan="2"><p>Basic Settings section</p></td></tr><tr><td><p>Display Name</p></td><td><p><code>Amazon SQS (Streaming)</code> or another name</p></td></tr><tr><td><p>Connector configuration*</p></td><td><p><code>Amazon_SQS_Configuration</code> (the reference name to the global element you created)</p></td></tr><tr><td><p>Queue url</p></td><td><p>Queue URL in the following format - <code><a href="https://sqs.region.amazonaws.com/account-id/queue-name">https://sqs.region.amazonaws.com/account-id/queue-name</a></code></p></td></tr><tr><td><p>Other fields in the <strong>General</strong> group</p></td><td><p>Default values</p></td></tr></tbody></table>

    Verify that the SQS queue in the configuration is **subscribed** to the SNS topic.

    For example:

    ![SNS SQS config](/mulesoft/current/en-us/amazon-sns-connector/4.7/_images/amazon-sns-sqs-config.png)

9.  Select the **Configuration XML** tab to view the corresponding XML:

    ```xml
    <sqs:receivemessages
      doc:name="Amazon SQS (Streaming)"
      queueUrl="https://sqs.us-east-1.amazonaws.com/123456789012/queue-url"
      config-ref="Amazon_SQS_Configuration"/>
    ```

10. Add a **Logger** scope after Amazon SQS Connector to print the data passed by the **Receive**
    operation in the Mule console. Configure the **Logger** as follows:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Parameter</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Display Name</strong></p></td><td><div><div><p><code>Display Message</code> or another name</p></div></div></td></tr><tr><td><p><strong>Message</strong></p></td><td><div><div><p><code>Received Message: #[payload]</code></p></div></div></td></tr><tr><td><p><strong>Level</strong></p></td><td><div><div><p><code>INFO</code></p></div></div></td></tr></tbody></table>

11. Save the project.

To run the project as a Mule app:

1.  Right-click the project in Package Explorer and select **Run As > Mule Application**.

2.  Open a web browser, enter the URL `http://localhost:8081/`, and check the response.

    The logger shows the published message ID on the browser and the received message on the Mule
    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. If needed, change the values to reflect your environment.

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

<mule xmlns:sqs="http://www.mulesoft.org/schema/mule/sqs"
	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.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/sns http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
http://www.mulesoft.org/schema/mule/sqs http://www.mulesoft.org/schema/mule/sqs/current/mule-sqs.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>
	<sns:config name="Amazon_SNS_configuration" doc:name="Amazon SNS configuration">
		<sns:basic-connection accessKey="EXAMPLEACCESSKEY" secretKey="EXAMPLESECRETKEY" />
	</sns:config>
	<sqs:config name="Amazon_SQS_Configuration" doc:name="Amazon SQS Configuration">
		<sqs:basic-connection accessKey="EXAMPLEACCESSKEY" secretKey="EXAMPLESECRETKEY"
		testQueueArn="arn:aws:sqs:us-east-1:123456789012:QueueName"/>
	</sqs:config>
	<flow name="sns-connector-exampleFlow">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/"/>
		<sns:publish doc:name="Publish" config-ref="Amazon_SNS_configuration"
		topicArn="arn:aws:sns:us-east-1:123456789012:TopicName"
		subject="Testing publish to queue"
		messageStructure="JSON">
			<sns:message><![CDATA[#['{
	"default": "Hello World!"
}']]]></sns:message>
		</sns:publish>
		<logger level="INFO" doc:name="Logger" message="Message: #[payload]"/>
	</flow>
	<flow name="sns-connector-exampleFlow1">
		<sqs:receivemessages doc:name="Amazon SQS (Streaming)" config-ref="Amazon_SQS_Configuration"
		queueUrl="https://sqs.us-east-1.amazonaws.com/123456789012/queue-url"/>
		<logger level="INFO" doc:name="Logger" message="Received Message: #[payload]"/>
	</flow>
</mule>
```

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
