Lecture 8
Lecture 8
LECTURE 8
Securely Connecting AWS IoT Devices to the Cloud
Handling AWS IoT Device Data and States
AWS IoT Scenario
Let’s begin by examining our use case. A food services company trucks ice
cream products to stores throughout the greater Seattle area. One of the biggest
challenges in the distribution process is maintaining the cold chain. Over the
past few months, their business has experienced 30 percent spoilage while the
products are in transit.
The problem could be with the truck refrigeration units turning off, high
summer temperatures, truck doors being left open, electrical issues, or
something they simply haven't thought of yet.
The company wants to use AWS IoT Core to monitor various aspects of truck
operation and determine the exact causes of the spoilage.
AWS IoT Core
AWS IoT Core is a managed cloud service.
With AWS IoT Core, you can securely connect devices with cloud applications
and other devices.
You can process and act on device data and build applications that interact with
devices even when they are offline.
You can also create applications where your users can control these devices
from their phones or other mobile devices.
Devices and data collection
Devices and data collection
Devices and data collection
Devices and data collection
Devices and data collection
Devices and data collection
Devices and data collection
Command and control of devices
Using AWS IoT Core, you can send commands and updates to your devices such
as updating firmware, changing device states, and restarting or shutting down
a device.
The bidirectional communication available in AWS IoT Core means that the
company could also send messages and alerts, such as the following:
◦ A text message to the driver to confirm whether the freezer door is fully closed and latched.
◦
A message to the truck to switch to the backup battery bank or to turn on a warning light in the cab if
the temperature in the truck falls below optimal levels.
Proof of concept
Armed with this knowledge, you will assist the company to create a proof of
concept. This will entail installing a single temperature sensor in the truck and
securely connecting the device to AWS IoT Core. Following this, you will
confirm that the sensor can publish messages to the cloud. The messages will
communicate the temperature in the back of the truck, the power going to the
freezer unit, and a timestamp.
Connected Devices to
AWS IOT Core
AWS IOT Core
Device gateway
The device gateway is responsible for the secure authentication and
authorization between AWS IoT Core and the various devices and applications
(also referred to as clients) connected to it.
IoT devices and clients need to communicate with each other and with the AWS
IoT services. A protocol called MQTT (Message Queuing and Telemetry
Transport) is used for this purpose.
MQTT is a lightweight, publish/subscribe communication protocol that is used
with IoT devices.
Message broker
The message broker is a high throughput publish-subscribe messaging agent
that securely transmits messages to and from all of your IoT devices and
applications with low latency based on the MQTT.
With the publish-subscribe model you can pick and choose the information you
want to gather. Clients send data by publishing a message on a topic.
Clients receive messages by subscribing to a topic.
Topics filter and select messages for reception. You define the name of the
topics, each one associated with some data point to publish-subscribe.
Security and identity
Security is mandatory for IoT systems and has two main components:
•Authentication: Verifies the identity of a user or service
•Authorization: Grants or denies the user or service permissions to access a resource
There are two areas where security must be applied in IoT systems.
AWS IoT certificates and policies
The first is within the AWS IoT workflow itself. This area of security uses AWS
IoT certificates and policies.
Devices and things, and the applications that communicate with them, must
authenticate themselves and must be authorized to perform their functions
(such as sending and receiving messages). Servers that handle communication
and messages, such as gateways and brokers, must also be authenticated and
authorized.
AWS IoT supports three types of identity principals for device or client
authentication. This course will focus on X.509 client certificates and IAM
users, groups, and roles.
Example
A temperature sensor is able to communicate with a mobile app through a message broker.
Authentication was done through certificates, and authorization was issued through AWS IoT
policies, which are attached to the certificate
IAM
In the second category, users (both human operators and software actors) need to interact with
the IoT system or with each other.
In this case, authentication and authorization are provided through the AWS Identity and Access
Management (IAM) service credentials or, in the case of third-party authentication.
Principle of least privilege
Controlling who can do what is mandatory in IoT systems. Access should only be
granted to authorized users, and they should have permissions limited to their
exact needs. For example, a system engineer might need to activate or
deactivate sensors, whereas an operator might only need to read sensor data
and gather data logs.
Device registry
The device registry is a database of devices. It catalogs static metadata and
attributes about the devices, such as serial numbers, manufacturer, firmware
version, internal identifiers, and device capabilities.
Using the registry for your devices is optional. You don't need to create an AWS
IoT thing in the registry to connect a device to AWS IoT. The registry, however,
enhances search capabilities by maintaining a list of devices and their
attributes. The registry can also publish event messages when things, thing
types, and thing groups are created, updated, or deleted.
You can search for and manage devices using the AWS IoT console, AWS IoT API,
or the AWS Command Line Interface (AWS CLI).
Organizing Devices and
Things
Provisioning devices
The temperature sensor device has been placed on the truck. The next step in the proof of
concept is to bring the devices online so they are ready to be used. This is called provisioning.
When you provision a device, you create and register a thing, which is a virtual representation
of the physical device in the cloud.
The information used to register the device within AWS IoT Core:
◦ Thing Name
◦ Thing attributes
◦ Thing type
Thing Name
All of your things must have a unique name in the same AWS Region.
Standardize your naming convention before the number of devices in your fleet grows too large.
Doing so simplifies management, communication, and access rights.
Thing attributes
Thing attributes are descriptive information about a thing such as function, location, technical
specifications, and so on.
Attributes, which are name-value pairs you can use to store information about the thing, such as
its serial number or manufacturer, can be helpful when searching for devices of particular type
or location.
When creating a thing, you can list up to three attributes. Using the device registry, you can
search your registered devices based on attributes and tags.
Thing type
Things can be assigned to thing types. A thing type organizes things into logical categories that
share common attributes, such as light bulbs, thermostats, and motion sensors.
Thing types can list up to 50 attributes, whereas things that aren't associated to a thing type have
only have three attributes. A thing can only be associated with one thing type. However, there is
no limit on the number of thing types you can create in your account.
Names for thing types do not require a universally unique name. However, they must be unique
within your account.
JSON data
JSON data
JSON data
JSON data
JSON data
Managing thing types
Thing types are immutable, which means the thing type name can't be changed
after it's created. If you need to change a thing type, first you deprecate the
existing thing type so no new things can be associated with it. Then,
disassociate all things from the existing thing type.
Finally, you create a new thing type that reflects the changes you want to make
and associate the things with this new thing type. You can then delete a thing
type with no things associated with it.
Thing groups
A thing group is a method to manage several things at once. Using thing groups, you can set
policies for your devices at an organizational level, instead of at the device level, and more
easily control or target updates and changes.
You can also create a hierarchy of groups—groups containing other groups. A thing can be a
member of up to 10 thing groups.
Thing groups Cont.
Securing Devices and
Authorizing action
Authorization and Authentication of IoT
Devices
When connecting devices to IoT Core, authentication and authorization perform different roles in
securing the devices. As previously discussed, there are two areas where security must be
applied in IoT systems:
• AWS IoT certificates and policies – Used for devices and things and the applications that communicate
with them
• IAM roles and policies – Used for both human operators and software actors that need to interact with
the IoT system or with each other
Device authorization
Authorization is the process of granting permissions to an authenticated identity.
After identities are authenticated, they still do not have permissions to access resources.
For devices and users to gain permissions, they must be authorized to do so.
This is achieved through use of AWS IoT policies
AWS IoT policies
Devices, mobile applications, web applications, and desktop applications all use an authenticated
identity. The identity can run AWS IoT operations only if it has a policy that grants it permission.
AWS IoT policies are attached to X.509 certificates. The policy defines what an authenticated
identity can do and grants the necessary permissions for the device to do its job.
AWS IoT policies primarily control a resource’s access to the AWS IoT Core data plane. When you
send data to and receive data from AWS IoT Core, you are using the AWS IoT Core data plane.
This means that the data plane defines whether you can connect to the message broker, send
or receive MQTT messages, or publish-subscribe to a specific topic.
IAM
In addition to the authentication and authorization of devices handled by AWS
IoT Core. IAM roles work with IAM policies to grant AWS IoT Core permissions
to access the rest of AWS.
Users (both human operators and software actors) need to interact with the IoT
system or with each other. In this case authentication and authorization are
provided through IAM policies that grant an IAM identity, or AWS resource,
permissions to access a service or perform a function with AWS.
◦ IAM roles and policies allow AWS IoT to access other AWS resources in your account on your behalf. For
example, if you want to have a device publish its state to an Amazon DynamoDB table, IAM roles allow
AWS IoT to interact with DynamoDB.
◦ Non-devices (mobile, web, or desktop applications) can authenticate with AWS IoT services, through
IAM users, groups, and roles. Web and desktop applications use IAM or federated identities. AWS CLI
commands use IAM.
IAM
AWS IoT policy format
AWS IoT policies define which AWS IoT Core actions can be taken by a
thing. Policies are JSON documents that contain a set of permissions. The
policies are then attached to the device, user, or role to give them the
permissions written in the policy.
An AWS IoT policy contains one or more policy statements. Each policy
statement contains the following three keys:
• Effect – Indicates whether the policy allows or denies access.
• Action – Includes a list of actions that the policy allows or denies.
• Resource – Specifies a list of resources to which the actions apply. If no resource is
listed, then the action applies to the resource to which the policy is attached.
Example
Policy actions
AWS IoT Core also defines a set of policy actions that describe the operations and resources to
which you can grant or deny access. Examples of actions include the following:
•iot:Connect represents permission to connect to the message broker.
Any string in the level that contains • Must be the only character in its level of the
+ the character. topic hierarchy.
• Can be used in multiple levels of a topic filter.
Wildcard topics using the Apartments
scenario
Wildcard topics using the ice cream
trucks scenario
An example of a broker
Defining the Message Broker
Defining the Message Broker
Defining the Message Broker
Defining the Message Broker
Defining the Message Broker
Defining the Message Broker
Back to our ice cream truck scenario
In our ice cream scenario, a temperature sensor can publish a message on the
topic about the temperature of the main freezer of the truck. The message is
relayed to IoT Core and is handled by the Message Broker.
The Message Broker is aware that there are subscriptions for this topic and
maintains a list of all client sessions and the subscriptions for each session.
When a message is published on a topic, the broker checks for sessions with
subscriptions that map to the topic. The broker then forwards the published
message to all sessions that have a currently connected client.
Data accumulation
Accumulating every bit of data from a sensor means that you will have a large amount of received
data. Imagine our scenario with our ice cream truck fleet with 10 trucks, each with five sensors. If
each sensor publishes, say, three elements of data (timestamp, temperature or door status, and
sensor health) every 15 seconds, this represents 60 data points every minute for each truck, so 600
pieces of information every minute.
Data Mining this data using AWS analytics services can provide some insight into the operation of the
fleet. These services help in operational monitoring, which is more of a reactive option, delayed in
time.
But for a day-to-day operation, with near real-time monitoring, there might be specific elements you
want to be aware of as they happen, to mitigate a situation or take a proper business decision backed
by data.
Imagine a sudden drop in temperature in a truck freezer. Having a direct notification of this specific
event would be helpful to the driver, while a review of the warehouse data feed would only show a
monthly average temperature for the month, not useful in the moment while a truck displays a
temperature drop at the moment.
Introducing rules
Taking actions on IoT data begins with rules in AWS IoT. Rules
are one of the primary methods of filtering and directing
communication from AWS IoT Core to other AWS services.