This directory contains sample applications for aws-iot-device-sdk-js-v2
- Browser 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 Signed Custom Authorizer Lambda Function | Example of connecting with a signed Lambda-backed custom authorizer. |
| AWS Unsigned Custom Authorizer Lambda Function | Example of connecting with an unsigned Lambda-backed custom authorizer. |
| PKCS11 | Demonstrates connecting using a hardware security module (HSM) or smartcard with PKCS#11. |
| Electron | Sample using Electron. |
| Other Connection Methods | More connection methods are available for review in the MQTT5 Userguide |
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. |
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. |
Node samples can be installed from the sample directory using the command:
npm installAnd then run using the command:
node dist/index.js <arguments>All NodeJS samples will show their options by passing in --help.
node dist/index.js --helpWhich will result in output showing all of the options that can be passed in at the command line, along with descriptions of what each does and whether they are optional or not.
To enable logging in the NodeJS samples, add the following code to the sample:
const level = parseInt(io.LogLevel["ERROR"]);
io.enable_logging(level);Note that the following log levels are available: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, and NONE. Once the code is added, logs will be printed to the console that then can be examined and shared to help debug issues.
If you are installing via npm instead of building from source, please make the following change to the package.json under each sample.
From:
"dependencies": {
"aws-iot-device-sdk-v2": "file:../../..",
"yargs": "^14.0.0"
}To:
"dependencies": {
"aws-iot-device-sdk-v2": "<latest released version eg: ^1.3.0>",
"yargs": "^14.0.0"
}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.