# AWS IoT Core to Amazon SNS to Amazon SQS This pattern contains a sample AWS SAM stack to create an IoT Rule with a SNS action, a SNS Topic and a SQS standard Queue subscribed to the SNS topic. When a message is published to the IoT topic defined in the IoT Rule, this message will be published to the SNS topic and finally the message will be delivered to the SQS queue subscribed to the SNS topic Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/iot-sns-sqs-sam Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. ## Requirements * [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured * [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) ## Deployment Instructions 1. Clone the project to your local working directory ```sh git clone https://github.com/aws-samples/serverless-patterns/ ``` 2. Change the working directory to this pattern's directory ```sh cd serverless-patterns/iot-sns-sqs-cfn ``` 1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: ``` sam deploy --guided --capabilities CAPABILITY_NAMED_IAM ``` 1. You can also use AWS CloudFormation console and paste the template.yml file in the designer and deploy it by passing the below required parameters. - Enter a stack name ## How it works When a message is published to the IoT topic defined in the IoT Rule, this message will be published to the SNS topic and finally the message will be delivered to the SQS queue subscribed to the SNS topic ## Testing Log into the AWS Console, browse to AWS IoT Core: 1. In the AWS IoT Core Console, in the `Test` section (left-side pane), select the `MQTT test client`. 2. Then under `Publish to a topic`, in the Topic filter field enter this: `device/data`, change the default Message payload to `{"default": "Hello from AWS IoT console"}`. Then click the `Publish` button. 3. In the AWS Console navigate to the SQS service. Select the SQS queue generated by the CFN stack (the name is in the format `iot-sns-sqs-cdk-IotSnsSqsCfnQueueXXXXXXX-XXXXX`) 4. In the `Receive messages` section, click on `Poll for messages`. This should display a new message. Click on the message ID and inspect the `Body` attributes which should contain the following: ```json { ... "message": "Hello from AWS IoT console" ... } ``` ## Cleanup 1. Delete the stack ```bash sam delete ``` ---- Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0