Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Sample Applications for the AWS IoT Device SDK v2 for Python

This directory contains sample applications for aws-iot-device-sdk-python-v2.

Table of Contents

Samples

MQTT5 Client Samples

MQTT5 is the recommended MQTT Client. Additional infomration and usage instructions can be found in the MQTT5 User Guide. The samples below will create an MQTT5 client, connect using the selected method, subscribe to a topic, publish to the topic, and then disconnect.
MQTT5 Client Sample Description
X509-based mutual TLS Demonstrates connecting to AWS IoT Core using X.509 certificates and private keys.
Websockets with Sigv4 authentication Shows how to authenticate over websockets using AWS Signature Version 4 credentials.
AWS Custom Authorizer Lambda Function Examples of connecting with a signed and unsigned Lambda-backed custom authorizer.
PKCS11 Demonstrates connecting using a hardware security module (HSM) or smartcard with PKCS#11.
Other Connection Methods More connection methods are available for review in the MQTT5 Userguide

Service Client Samples

AWS offers a number of IoT related services using MQTT. The samples below demonstrate how to use the service clients provided by the SDK to interact with those services.
Service Client Sample Description
Shadow Manage and sync device state using the IoT Device Shadow service.
Jobs Receive and execute remote operations sent from the Jobs service.
Basic Fleet Provisioning Provision a device using the Fleet Provisioning template.
CSR Fleet Provisioning Demonstrates CSR-based device certificate provisioning.

Greengrass Samples

Samples that interact with AWS Greengrass.
Greengrass Sample Description
Greengrass Discovery Discover and connect to a local Greengrass core.
Greengrass IPC Demonstrates Inter-Process Communication (IPC) with Greengrass components.

Instructions

First, install aws-iot-device-sdk-python-v2. Installation instructions for the SDK are Provided Here.

Each sample's README contains prerequisites, arguments, and detailed instructions. For example, the MQTT5 X509 Sample README is mqtt5_x509.md and the sample can be run with the following command:

# For Windows: replace 'python3' with 'python' and '/' with '\'
python3 mqtt5_x509.py --endpoint <endpoint> --cert <path to certificate> --key <path to private key>

Sample Help

All samples will show their options and arguments by passing in --help. For example:

# For Windows: replace 'python3' with 'python' and '/' with '\'
python3 mqtt5_x509.py --help

will result in the following print output:

MQTT5 X509 Sample (mTLS)

options:
  -h, --help    show this help message and exit

required arguments:
  --endpoint    IoT endpoint hostname (default: None)
  --cert        Path to the certificate file to use during mTLS connection establishment (default: None)
  --key         Path to the private key file to use during mTLS connection establishment (default: None)

optional arguments:
  --client_id   Client ID (default: mqtt5-sample-5873a450)
  --topic       Topic (default: test/topic)
  --message     Message payload (default: Hello from mqtt5 sample)
  --count       Messages to publish (0 = infinite) (default: 5)

The sample will not run without the required arguments and will notify you of missing arguments.

Enable Logging

Instructions to enable logging are available in the FAQ under How do I enable logging.

⚠️ Usage disclaimer

These code examples interact with services that may incur charges to your AWS account. For more information, see AWS Pricing.

Additionally, example code might theoretically modify or delete existing AWS resources. As a matter of due diligence, do the following:

  • Be aware of the resources that these examples create or delete.
  • Be aware of the costs that might be charged to your account as a result.
  • Back up your important data.