From Some more on AWS IoT. It’s a little difficult to simplify what’s going on, but I think this is pretty good. At the highest level, think of it this way: AWS IoT recieves messages and routes them based on rules to other AWS services
Here’s the basic workflow of AWS IoT. It’s a simplification and leaves out a number of important services, but this is the core of it. Understanding this is to understand what AWS IOT can do … and what it can do for you.
Here’s the workflow:
- your Things send messages
- the Device Gateway receives and authenticates the messages
- the Rules Engine authorizes the messages and then routes them to other AWS services
A message in AWS IoT consists of two principal parts:
- a path, which looks like a UNIX path without the leading “/”
- a payload, which is a JSON message
This message is augmented with authorization information as it flows through AWS IoT.
What follows is some interesting proof of concept stuff, but you can also checkout this workshop.
- Go to “IAM” in the AWS management console and create a new user first, attaching the pre-defined AWSIoTDataAccess policy.
- clone this Gist
- adjust the constants declared at the top of main.js as needed
- use the created IAM user with the
AWSIoTDataAccess
policy - for the endpoint host run
aws iot describe-endpoint
CLI command
- use the created IAM user with the
- run
npm install
- run
./node_modules/.bin/webpack-dev-server --colors
This was just the first (big) part. There’s more stuff left to be done:
- neither is hard-coding AWS credentials into the application source the way to go nor is publishing the secret key at all
- … one possible approach would be to use the API Gateway + Lambda to create pre-signed URLs
- … this could be further limited by using IAM roles and temporary identity federation (through STS Token Service)
- there’s no user authentication yet, this should be achievable with AWS Cognito
- … with that publishing/subscribing could be limited to identity-related topics (depends on the use case)
To create an IAM group and add a new IAM user to it
$ aws iam create-group --group-name MyIamGroup
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2012-12-20T03:03:52.834Z",
"GroupId": "AKIAI44QH8DHBEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
}
}
$ aws iam create-user --user-name MyUser
{
"User": {
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2012-12-20T03:13:02.581Z",
"UserId": "AKIAIOSFODNN7EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
}
$ aws iam add-user-to-group --user-name MyUser --group-name MyIamGroup
$ aws iam get-group --group-name MyIamGroup
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2012-12-20T03:03:52Z",
"GroupId": "AKIAI44QH8DHBEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
},
"Users": [
{
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2012-12-20T03:13:02Z",
"UserId": "AKIAIOSFODNN7EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
],
"IsTruncated": "false"
}
You can also view IAM users and groups with the AWS Management Console.
$ aws iam put-user-policy --user-name MyUser --policy-name MyPowerUserRole --policy-document file://C:\Temp\MyPolicyFile.json
Verify the policy has been assigned to the user with the list-user-policies command.
$ aws iam list-user-policies --user-name MyUser
{
"PolicyNames": [
"MyPowerUserRole"
],
"IsTruncated": "false"
}
See article here: http://stesie.github.io/2016/04/aws-iot-pubsub