Amazon SNS - Amazon IoT Greengrass
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Amazon SNS

The Amazon SNS component (aws.greengrass.SNS) publishes messages to an Amazon Simple Notification Service (Amazon SNS) topic. You can use this component to send events from Greengrass core devices to web servers, email addresses, and other message subscribers. For more information, see What is Amazon SNS? in the Amazon Simple Notification Service Developer Guide.

To publish to an Amazon SNS topic with this component, publish a message to the topic where this component subscribes. By default, this component subscribes to the sns/message local publish/subscribe topic. You can specify other topics, including Amazon IoT Core MQTT topics, when you deploy this component.

In your custom component, you might want to implement filtering or formatting logic to process messages from other sources before you publish them to this component. This enables you to centralize your message processing logic on a single component.

Note

This component provides similar functionality to the Amazon SNS connector in Amazon IoT Greengrass V1. For more information, see Amazon SNS connector in the Amazon IoT Greengrass V1 Developer Guide.

Versions

This component has the following versions:

  • 2.1.x

  • 2.0.x

Type

This component is a Lambda component (aws.greengrass.lambda). The Greengrass nucleus runs this component's Lambda function using the Lambda launcher component.

For more information, see Component types.

Operating system

This component can be installed on Linux core devices only.

Requirements

This component has the following requirements:

  • Your core device must meet the requirements to run Lambda functions. If you want the core device to run containerized Lambda functions, the device must meet the requirements to do so. For more information, see Lambda function requirements.

  • Python version 3.7 installed on the core device and added to the PATH environment variable.

  • An Amazon SNS topic. For more information, see Creating an Amazon SNS topic in the Amazon Simple Notification Service Developer Guide.

  • The Greengrass device role must allow the sns:Publish action, as shown in the following example IAM policy.

    { "Version": "2012-10-17", "Statement": [ { "Action": [ "sns:Publish" ], "Effect": "Allow", "Resource": [ "arn:aws-cn:sns:region:account-id:topic-name" ] } ] }

    You can dynamically override the default topic in the input message payload for this component. If your application uses this feature, the IAM policy must include all target topics as resources. You can grant granular or conditional access to resources (for example, by using a wildcard * naming scheme).

  • To receive output data from this component, you must merge the following configuration update for the legacy subscription router component (aws.greengrass.LegacySubscriptionRouter) when you deploy this component. This configuration specifies the topic where this component publishes responses.

    Legacy subscription router v2.1.x
    { "subscriptions": { "aws-greengrass-sns": { "id": "aws-greengrass-sns", "source": "component:aws.greengrass.SNS", "subject": "sns/message/status", "target": "cloud" } } }
    Legacy subscription router v2.0.x
    { "subscriptions": { "aws-greengrass-sns": { "id": "aws-greengrass-sns", "source": "arn:aws-cn:lambda:region:aws:function:aws-greengrass-sns:version", "subject": "sns/message/status", "target": "cloud" } } }
    • Replace region with the Amazon Web Services Region that you use.

    • Replace version with the version of the Lambda function that this component runs. To find the Lambda function version, you must view the recipe for the version of this component that you want to deploy. Open this component's details page in the Amazon IoT Greengrass console, and look for the Lambda function key-value pair. This key-value pair contains the name and version of the Lambda function.

    Important

    You must update the Lambda function version on the legacy subscription router every time you deploy this component. This ensures that you use the correct Lambda function version for the component version that you deploy.

    For more information, see Create deployments.

  • The Amazon SNS component is supported to run in a VPC. To deploy this component in a VPC, the following is required.

    • The Amazon SNS component must have connectivity to sns.region.amazonaws.com which has the VPC endpoint of com.amazonaws.us-east-1.sns.

Endpoints and ports

This component must be able to perform outbound requests to the following endpoints and ports, in addition to endpoints and ports required for basic operation. For more information, see Allow device traffic through a proxy or firewall.

Endpoint Port Required Description

sns.region.amazonaws.com

443 Yes

Publish messages to Amazon SNS.

Dependencies

When you deploy a component, Amazon IoT Greengrass also deploys compatible versions of its dependencies. This means that you must meet the requirements for the component and all of its dependencies to successfully deploy the component. This section lists the dependencies for the released versions of this component and the semantic version constraints that define the component versions for each dependency. You can also view the dependencies for each version of the component in the Amazon IoT Greengrass console. On the component details page, look for the Dependencies list.

2.1.7

The following table lists the dependencies for version 2.1.7 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.13.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.6

The following table lists the dependencies for version 2.1.6 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.12.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.5

The following table lists the dependencies for version 2.1.5 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.11.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.4

The following table lists the dependencies for version 2.1.4 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.10.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.3

The following table lists the dependencies for version 2.1.3 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.9.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.2

The following table lists the dependencies for version 2.1.2 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.8.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.1.1

The following table lists the dependencies for version 2.1.1 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.7.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.8 - 2.1.0

The following table lists the dependencies for versions 2.0.8 and 2.1.0 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.6.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.7

The following table lists the dependencies for version 2.0.7 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.5.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.6

The following table lists the dependencies for version 2.0.6 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.4.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.5

The following table lists the dependencies for version 2.0.5 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.3.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.4

The following table lists the dependencies for version 2.0.4 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.0 <2.2.0 Hard
Lambda launcher ^2.0.0 Hard
Lambda runtimes ^2.0.0 Soft
Token exchange service ^2.0.0 Hard
2.0.3

The following table lists the dependencies for version 2.0.3 of this component.

Dependency Compatible versions Dependency type
Greengrass nucleus >=2.0.3 <2.1.0 Hard
Lambda launcher >=1.0.0 Hard
Lambda runtimes >=1.0.0 Soft
Token exchange service >=1.0.0 Hard

For more information about component dependencies, see the component recipe reference.

Configuration

This component provides the following configuration parameters that you can customize when you deploy the component.

Note

This component's default configuration includes Lambda function parameters. We recommend that you edit only the following parameters to configure this component on your devices.

lambdaParams

An object that contains the parameters for this component's Lambda function. This object contains the following information:

EnvironmentVariables

An object that contains the Lambda function's parameters. This object contains the following information:

DEFAULT_SNS_ARN

The ARN of the default Amazon SNS topic where this component publishes messages. You can override the destination topic with the sns_topic_arn property in the input message payload.

containerMode

(Optional) The containerization mode for this component. Choose from the following options:

  • NoContainer – The component doesn't run in an isolated runtime environment.

  • GreengrassContainer – The component runs in an isolated runtime environment inside the Amazon IoT Greengrass container.

Default: GreengrassContainer

containerParams

(Optional) An object that contains the container parameters for this component. The component uses these parameters if you specify GreengrassContainer for containerMode.

This object contains the following information:

memorySize

(Optional) The amount of memory (in kilobytes) to allocate to the component.

Defaults to 512 MB (525,312 KB).

pubsubTopics

(Optional) An object that contains the topics where the component subscribes to receive messages. You can specify each topic and whether the component subscribes to MQTT topics from Amazon IoT Core or local publish/subscribe topics.

This object contains the following information:

0 – This is an array index as a string.

An object that contains the following information:

type

(Optional) The type of publish/subscribe messaging that this component uses to subscribe to messages. Choose from the following options:

  • PUB_SUB – Subscribe to local publish/subscribe messages. If you choose this option, the topic can't contain MQTT wildcards. For more information about how to send messages from custom component when you specify this option, see Publish/subscribe local messages.

  • IOT_CORE – Subscribe to Amazon IoT Core MQTT messages. If you choose this option, the topic can contain MQTT wildcards. For more information about how to send messages from custom components when you specify this option, see Publish/subscribe Amazon IoT Core MQTT messages.

Default: PUB_SUB

topic

(Optional) The topic to which the component subscribes to receive messages. If you specify IotCore for type, you can use MQTT wildcards (+ and #) in this topic.

Example: Configuration merge update (container mode)
{ "lambdaExecutionParameters": { "EnvironmentVariables": { "DEFAULT_SNS_ARN": "arn:aws-cn:sns:us-west-2:123456789012:mytopic" } }, "containerMode": "GreengrassContainer" }
Example: Configuration merge update (no container mode)
{ "lambdaExecutionParameters": { "EnvironmentVariables": { "DEFAULT_SNS_ARN": "arn:aws-cn:sns:us-west-2:123456789012:mytopic" } }, "containerMode": "NoContainer" }

Input data

This component accepts messages on the following topic and publishes the message as is to the target Amazon SNS topic. By default, this component subscribes to local publish/subscribe messages. For more information about how to publish messages to this component from your custom components, see Publish/subscribe local messages.

Default topic (local publish/subscribe): sns/message

The message accepts the following properties. Input messages must be in JSON format.

request

The information about the message to send to the Amazon SNS topic.

Type: object that contains the following information:

message

The content of the message as a string.

To send a JSON object, serialize it as a string, and specify json for the message_structure property.

Type: string

subject

(Optional) The subject of the message.

Type: string

The subject can be ASCII text and up to 100 characters. It must begin with a letter, number, or punctuation mark. It can't include line breaks or control characters.

sns_topic_arn

(Optional) The ARN of the Amazon SNS topic where this component publishes the message. Specify this property to override the default Amazon SNS topic.

Type: string

message_structure

(Optional) The structure of the message. Specify json to send a JSON message that you serialize as a string in the content property.

Type: string

Valid values: json

id

An arbitrary ID for the request. Use this property to map an input request to an output response. When you specify this property, the component sets the id property in the response object to this value.

Type: string

Note

The message size can be a maximum of 256 KB.

Example input: String message
{ "request": { "subject": "Message subject", "message": "Message data", "sns_topic_arn": "arn:aws-cn:sns:region:account-id:topic2-name" }, "id": "request123" }
Example input: JSON message
{ "request": { "subject": "Message subject", "message": "{ \"default\": \"Message data\" }", "message_structure": "json" }, "id": "request123" }

Output data

This component publishes responses as output data on the following MQTT topic by default. You must specify this topic as the subject in the configuration for the legacy subscription router component. For more information about how to subscribe to messages on this topic in your custom components, see Publish/subscribe Amazon IoT Core MQTT messages.

Default topic (Amazon IoT Core MQTT): sns/message/status

Example output: Success
{ "response": { "sns_message_id": "f80a81bc-f44c-56f2-a0f0-d5af6a727c8a", "status": "success" }, "id": "request123" }
Example output: Failure
{ "response" : { "error": "InvalidInputException", "error_message": "SNS Topic Arn is invalid", "status": "fail" }, "id": "request123" }

Local log file

This component uses the following log file.

/greengrass/v2/logs/aws.greengrass.SNS.log
To view this component's logs
  • Run the following command on the core device to view this component's log file in real time. Replace /greengrass/v2 with the path to the Amazon IoT Greengrass root folder.

    sudo tail -f /greengrass/v2/logs/aws.greengrass.SNS.log

Licenses

This component includes the following third-party software/licensing:

This component is released under the Greengrass Core Software License Agreement.

Changelog

The following table describes the changes in each version of the component.

Version

Changes

2.1.7

Version updated for Greengrass nucleus version 2.12.0 release.

2.1.6

Version updated for Greengrass nucleus version 2.11.0 release.

2.1.5

Version updated for Greengrass nucleus version 2.10.0 release.

2.1.4

Version updated for Greengrass nucleus version 2.9.0 release.

2.1.3

Version updated for Greengrass nucleus version 2.8.0 release.

2.1.2

Version updated for Greengrass nucleus version 2.7.0 release.

2.1.1

Version updated for Greengrass nucleus version 2.6.0 release.

2.1.0

New features

2.0.8

Version updated for Greengrass nucleus version 2.5.0 release.

2.0.7

Version updated for Greengrass nucleus version 2.4.0 release.

2.0.6

Version updated for Greengrass nucleus version 2.3.0 release.

2.0.5

Version updated for Greengrass nucleus version 2.2.0 release.

2.0.4

Version updated for Greengrass nucleus version 2.1.0 release.

2.0.3

Initial version.