Menu
AWS Greengrass
Developer Guide

Create a Subscription Definition

The subscription definition is a collection of subscriptions to be deployed to the AWS Greengrass group. These subscriptions dictate how messages will be sent and received within the AWS Greengrass group. Messages are sent between a source and a target only if there is a subscription for the source and target in the subscription definition.

First, create a subscription definition using the create-subscription-definition CLI command:

Copy
aws greengrass create-subscription-definition --name "MySubscriptionDefinition"

The --name argument specifies the name of the subscription definition.

The output of create-subscription-definition command looks like this:

Copy
{ "LastUpdatedTimestamp": "2017-05-17T20:20:40.534Z", "CreationTimestamp": "2017-05-17T20:20:40.534Z", "Id": "17d6cb13-3745-496c-9187-29316b37115e", "Arn":"arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/subscriptions/17d6cb13-3745-496c-9187-29316b37115e", "Name": "<MySubscriptionDefinition>" }

Now create a version of the subscription definition by adding subscriptions:

Copy
aws greengrass create-subscription-definition-version --subscription-definition-id "<SubscriptionDefinitionId>" --subscriptions '[ { "Id": "1", "Source": "<Switch_Thing-arn>", "Subject": "$aws/things/RobotArm_Thing/shadow/update", "Target": "GGShadowService" }, { "Id": "2", "Source": "<RobotArm_Thing-arn>", "Subject": "/topic/state", "Target": "<uptimeLambda-arn>" }, { "Id": "3", "Source": "<RobotArm_Thing-arn>", "Subject": "$aws/things/RobotArm_Thing/shadow/update", "Target": "GGShadowService" }, { "Id": "4", "Source": "GGShadowService", "Subject": "$aws/things/RobotArm_Thing/shadow/update/delta", "Target": "<RobotArm_Thing-arn>" }, { "Id": "5", "Source": "<uptimeLambda-arn>", "Subject": "/topic/metering", "Target": "cloud" }, { "Id": "6", "Source": "<messageLambda-arn>", "Subject": "$aws/things/RobotArm_Thing/shadow/update", "Target": "GGShadowService" }, { "Id": "7", "Source": "cloud", "Subject": "/topic/update", "Target": "<messageLambda-arn>" }, { "Id": "8", "Source": "GGShadowService", "Subject": "$aws/things/RobotArm_Thing/shadow/update/accepted", "Target": "<Switch_Thing-arn>" }, { "Id":"9", "Source":"GGShadowService", "Subject":"$aws/things/RobotArm_Thing/shadow/update/rejected", "Target": "<Switch_Thing-arn>" }, { "Id":"10", "Source":"GGShadowService", "Subject": "$aws/things/RobotArm_Thing/shadow/update/accepted", "Target": "<RobotArm_Thing-arn>" }, { "Id":"11", "Source":"GGShadowService", "Subject": "$aws/things/RobotArm_Thing/shadow/update/rejected", "Target": "<RobotArm_Thing-arn>" } ]'

Arguments for the create-subscription-definition-version CLI command:

--subscription-definition-id

The subscription definition ID.

--subscriptions

A JSON object that defines the subscription.

Id

The element ID for this entry in the list.

Source

The source of the message.

Subject

The MQTT topic used to filter messages.

Target

The recipient of the message.

The output from the create-subscription-definition-version CLI command will look like this:

Copy
{ "Arn" : "arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/subscriptions/17d6cb13-3745-496c-9187-29316b37115e/versions/0ad227b8-3d1d-43f6-bcc9-446201386e69", "Id" : "17d6cb13-3745-496c-9187-29316b37115e", "Version" : "0ad227b8-3d1d-43f6-bcc9-446201386e69", "CreationTimestamp" : "2017-05-17T21:15:00.350Z" }

You can view a subscription definition using the get-subscription-definition-version CLI command:

Copy
aws greengrass get-subscription-definition-version --subscription-definition-id "<SubscriptionDefinitionId>" --subscription-definition-version-id "<SubscriptionDefinitionVersion>"

Arguments for the get-subscription-definition-version CLI command:

--subscription-definition-id

The subscription definition ID.

--subscription-definition-version-id

The ID of the subscription definition version.

The output of the get-subscription-definition-version CLI command will look like this:

Copy
{ "Definition": { "Subscriptions": [ { "Source": "<Switch_Thing-arn>", "Target": "GGShadowService", "Id": "1", "Subject": "$aws/things/RobotArm_Thing/shadow/update" }, { "Source": "GGShadowService", "Target": "<RobotArm_Thing-arn>", "Id": "10", "Subject": "$aws/things/RobotArm_Thing/shadow/update/accepted" }, { "Source": "GGShadowService", "Target": "<RobotArm_Thing-arn>", "Id": "11", "Subject": "$aws/things/RobotArm_Thing/shadow/update/rejected" }, { "Source": "<RobotArm_Thing-arn>", "Target": "<uptimeLambda-arn>", "Id": "2", "Subject": "/topic/state" }, { "Source": "<RobotArm_Thing-arn>", "Target": "GGShadowService", "Id": "3", "Subject": "$aws/things/RobotArm_Thing/shadow/update" }, { "Source": "GGShadowService", "Target": "<RobotArm_Thing-arn>", "Id": "4", "Subject": "$aws/things/RobotArm_Thing/shadow/update/delta" }, { "Source": "<uptimeLambda-arn>", "Target": "cloud", "Id": "5", "Subject": "/topic/metering" }, { "Source": "<messageLambda-arn>", "Target": "GGShadowService", "Id": "6", "Subject": "$aws/things/RobotArm_Thing/shadow/update" }, { "Source": "cloud", "Target": "<messageLambda-arn>", "Id": "7", "Subject": "/topic/update" }, { "Source": "GGShadowService", "Target": "<Switch_Thing-arn>", "Id": "8", "Subject": "$aws/things/RobotArm_Thing/shadow/update/accepted" }, { "Source": "GGShadowService", "Target": , "Id": "9", "Subject": "$aws/things/RobotArm_Thing/shadow/update/rejected" } ] }, "Version": "0ad227b8-3d1d-43f6-bcc9-446201386e69", "CreationTimestamp": "2017-05-17T21:15:00.350Z", "Id": "17d6cb13-3745-496c-9187-29316b37115e", "Arn": "arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/subscriptions/17d6cb13-3745-496c-9187-29316b37115e/versions/0ad227b8-3d1d-43f6-bcc9-446201386e69" }