|
| 1 | +# Serverless IoT Event |
| 2 | + |
| 3 | +This example demonstrates how to setup a AWS IoT Rule to send events to a Lambda function. |
| 4 | + |
| 5 | +## Use-cases |
| 6 | + |
| 7 | +- Analytics for IoT events |
| 8 | +- Reacting on IoT events |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +In order to deploy the function simply run |
| 13 | + |
| 14 | +```bash |
| 15 | +serverless deploy |
| 16 | +``` |
| 17 | + |
| 18 | +The expected result should be similar to: |
| 19 | + |
| 20 | +```bash |
| 21 | +Serverless: Packaging service... |
| 22 | +Serverless: Uploading CloudFormation file to S3... |
| 23 | +Serverless: Uploading service .zip file to S3 (363 B)... |
| 24 | +Serverless: Updating Stack... |
| 25 | +Serverless: Checking Stack update progress... |
| 26 | +................ |
| 27 | +Serverless: Stack update finished... |
| 28 | +Service Information |
| 29 | +service: aws-node-iot-event |
| 30 | +stage: dev |
| 31 | +region: us-east-1 |
| 32 | +api keys: |
| 33 | + None |
| 34 | +endpoints: |
| 35 | + None |
| 36 | +functions: |
| 37 | + aws-node-iot-event-dev-log: arn:aws:lambda:us-east-1:377024778620:function:aws-node-iot-event-dev-log |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +In `serverless.yml` the log-function is configured to receive any event from the IoT Topic `my-button`. We now can go to the IoT Console and visit the Tab `Test`. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +There fill `mybutton` into the topic input field in the publish section. Replace existing example data with the following example and press the publish button. |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "message": "My first IoT event", |
| 51 | + "value": 2 |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +To verify that our event was forwarded to our log-function run |
| 58 | + |
| 59 | +```bash |
| 60 | +serverless logs --function log |
| 61 | +``` |
| 62 | + |
| 63 | +The expected result should be similar to: |
| 64 | + |
| 65 | +```bash |
| 66 | +START RequestId: 24192153-d10f-11e6-936c-a98ff4127599 Version: $LATEST |
| 67 | +2017-01-02 18:16:04.768 (+01:00) 24192153-d10f-11e6-936c-a98ff4127599 { message: 'My first IoT event', value: 2 } |
| 68 | +END RequestId: 24192153-d10f-11e6-936c-a98ff4127599 |
| 69 | +REPORT RequestId: 24192153-d10f-11e6-936c-a98ff4127599 Duration: 23.53 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 8 MB |
| 70 | +``` |
| 71 | +
|
| 72 | +In the output you can see the IoT event that has been triggered from the test console. |
0 commit comments