Lets say I want to have a staging environment and a production environment. The application works by adding topic rules and processes the ingest with AWS lambda.
What is the best way to have multiple environments in AWS IoT Core?
I thought about doing this:
dev/*
or prod/*
I would strongly prefer 3. as it allows me to also use production devices for testing. 1. and 2. are alright but not very flexible.
Maybe there are some best practices?
AWS IoT Core makes it easy to use AWS services such as AWS Lambda, Amazon Kinesis, Amazon S3, Amazon SageMaker, Amazon DynamoDB,Amazon CloudWatch, AWS CloudTrail, and Amazon QuickSight to build Internet of IoT applications that gather, process, analyze and act on data generated by connected devices, without having to ...
AWS IoT Greengrass enables your devices to collect and analyze data closer to where that data is generated, react autonomously to local events, and communicate securely with other devices on the local network. Greengrass devices can also communicate securely with AWS IoT Core and export IoT data to the AWS Cloud.
The AWS IoT Core MQTT broker and AWS IoT Device SDK are also compliant with the MQTT 3.1. 1 standard, so you can use these features to create an application that uses MQTT 3.1. 1 across your devices and the AWS Cloud. Choose this option to use MQTT 5 features in communication between core devices and client devices.
We have experienced the stage topic prefix approach in our project for months. I think we keep doing it but there are some side effects that I have mentioned below.
Most of the time messages will routed to IoTCore Rules and will trigger some AWS services like Lambda/S3/Dynamo etc. If you are using serverless this could achive with env variables as follows
...
custom:
myStage: ${opt:stage, self:provider.stage}
STAGES:
- dev
- prod
provider:
name: aws
runtime: nodejs12.x
region: eu-central-1
environment:
STAGE: ${self:custom.myStage}
functions:
someLambdaFunction:
timeout: 180
handler: someLambdaFunction.handler
events:
- iot:
name: "iotRuleName_${self:custom.myStage}"
sqlVersion: "2016-03-23"
sql: "SELECT * as data , topic() as topicName FROM '${self:custom.myStage}/room/+/temperature'"
So when you deploy to serverless app to development environment, the rule name will be iotRuleName_dev
and the rule sql will be like dev/room/+/temperature
But there are some problems:
As you say with this approach, endnodes should know the prefix value.
AWS limits your topic levels as 8 -max 7 forward slashes(/) - so by adding stage as prefix to all topics you basically decrease your limit to 7 AWS IoT Core Quotas
You still have to check for thingName collision. You cant have same thingName in multiple environments at the same time and you would not want to deal with it. Adding stage prefix to thing names could solve confusion. Something like 'DEV-Thing1'
You would also want to consider using basic ingest to reduce costs
It could also possible to split your whole application environments between AWS regions, No collision, no side effects. But you should almost split everything to sleep well in your bad at night. Because accessing different regions entities could cause a big chaos.
Build your own IoT Core. Well, if you achive this. Do not only use it but sell it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With