How to stream IoT & telematics data to Amazon AWS?

Sending telemetry data from flespi to the Amazon AWS IoT Core.

Forwarding the data from telematics/IoT devices into the Amazon AWS IoT Core is a common task that, when complete, opens immense opportunities for handling the data in the Amazon ecosystem. Once the data from your device(s) appears in flespi, sending it to AWS is fast and straightforward.

In this blog post, we describe an alternative way to send data to AWS SQS queue via AWS Lambda using the HTTP stream.

Prerequisites

  • Flespi channel working over the appropriate protocol to collect the data from your IoT/telematics hardware.

  • Flespi device to have a virtual representation of each physical device in the flespi platform with dedicated long-term storage, access to telemetry, real-time analytics capabilities, and more.

  • Registered account with Amazon AWS IoT Core to set up the receiving side.

AWS IoT thing configuration

Note: you can follow the original guide from AWS here or our steps below.

On the Amazon side, we start from the AWS Management Console:

aws management console

Go to the Connect an IoT device section.

Once in the AWS IoT section, unfold the Manage left-side menu and select the Things item. Click on the Register a thing button.

aws iot register a thing

Then you decide whether you want to create one thing or several things in bulk. For demonstration purposes we create one thing:

register a single aws iot thing

The minimum information you should provide to create a thing is its name:

aws iot thing config

On the next step of the thing creation, you should generate a certificate to authenticate your device's connection to AWS IoT:

aws iot certificate create

Download all generated files and store them in a safe place. You will need XXXXXXXX-certificate.pem.crt and XXXXXXXX-private.pem.key certificates to configure the aws_iot stream in flespi.

Then click the Activate button to activate the certificate.

Click Done to finalize the thing creation.

aws iot certificate download activate

This is our newly created thing:

aws iot thing created

Next, we need to create a policy (see AWS docs here) to define things permission to access AWS IoT resources. Go to Secure -> Policies -> Create a policy:

aws iot policy create

For ease of demonstration we can simply grant full access:

aws iot policy access rights

And here’s our policy

aws iot policy created

Now we need to attach the policy and the thing to the certificate.

Open Secure -> Certificates. Click on the three dots for the certificate and select Attach policy:

aws iot certificate attach policy

Pick the policy we’ve created and click Attach:

aws iot certificate policy attached

Then we follow a similar process to attach a thing - click on the three dots for the certificate and select Attach thing:

aws iot certificate policy thing attach

Pick the thing we’ve created and click Attach:

aws iot certificate policy thing attached

Fast-forward way to configure a thing

Once in the AWS IoT section, unfold the Onboard left-side menu and select the Get started item. Click on the Get started button for the Onboard a device option.

aws iot onboard a device

Note: on the AWS side we are using the following API: https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html#update-pub-sub-topic

Flespi AWS stream configuration

Back to flespi now. We are ready to create an aws_iot stream

Go to Telematics hub -> Streams -> green “+” button.

flespi aws_iot stream create configure

Give your stream a name.

Pick the “aws_iot” protocol ID.

Find the Endpoint in the AWS IoT Console -> Settings.

aws iot settings endpoint

Copy and paste the content of the previously downloaded XXXXXXXX-certificate.pem.crt and XXXXXXXX-private.pem.key files into the certificate and private key fields respectively.

Click Save and the new stream will appear in the streams list. It should turn green shortly.

Click on the newly created stream and go to the Logs tab:

flespi aws_iot stream toolbox tab

You should see the “stream connected successfully” log record that means the connection with AWS was established and the stream is ready to send messages. If you see any red line you may check the raw traffic and analyze responses from AWS side for more details but the most common problem is the authorization and incorrectly configured device policy.

Now we can assign a device to the stream to start sending messages.

Switch to the Devices tab, click the green “+” button and pick the device you need:

flespi stream assign device

If you switch back to the Logs tab after that, you should see the confirmation that the messages are dispatching to AWS:

flespi aws_iot stream toolbox tab sent messages

What’s in AWS?

Go to the Test section, type the MQTT topic we specified in the “aws_iot” stream configuration (we used “test_data”) and click Subscribe to topic:

aws iot mqtt client test subscribe to topic

AWS stream automatically publishes to the topic to update the shadow. The topic has a format '$aws/things/{thing-name}/shadow/update' and payload format is '{"reported":{...}}'.

If your device is actively sending new messages, you should shortly see them here:

aws iot mqtt client message from flespi device

Troubleshooting

If the Logs tab for the AWS stream shows successful connects followed by disconnects repeatedly, the problem is most likely with the configuration of the AWS policies:

flespi aws stream toolbox disconnects

Should you experience any other difficulties when establishing communication with AWS, tell us about the issue in the Helpbox chat.

***

Now that the device data is in the AWS thing, you can apply all the vast capabilities of the Amazon AWS IoT Core ecosystem to process and handle it as per your business needs.

To deliver only certain messages, parameters in it or convert message parameter names into different notation read generic stream configuration.


See also
Sending telemetry data from flespi to RabbitMQ or other AMQP 0-9-1 Broker.
Sending telemetry data from flespi to the GpsGate tracking system.