You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for AWS IoT to send and receive messages through an MQTT connection using MQTT5 and a websocket as transport. AWS Websocket requires the initial handshake request to be signed with the AWS Sigv4 signing algorithm. [`AwsCredentialsProvider.new_default_chain`](https://github.com/awslabs/aws-crt-python/blob/main/awscrt/auth.py) is used to source credentials via the default credentials provider chain to sign the websocket handshake.
14
+
15
+
You can read more about MQTT5 for the Python IoT Device SDK V2 in the [MQTT5 user guide](../../documents/MQTT5_Userguide.md).
16
+
17
+
## Requirements
18
+
19
+
The AWS IAM permission policy associated with the AWS credentials resolved by the default credentials provider chain must provide privileges for the sample to connect, subscribe, publish, and receive. Below is a sample policy will allow this sample to run as intended.
Replace with the following with the data from your AWS account:
60
+
*`<region>`: The AWS IoT Core region where you created your AWS IoT Core thing you wish to use with this sample. For example `us-east-1`.
61
+
*`<account>`: Your AWS IoT Core account ID. This is the set of numbers in the top right next to your AWS account name when using the AWS IoT Core website.
62
+
63
+
Note that in a real application, you may want to avoid the use of wildcards in your ClientID or use them selectively. Please follow best practices when working with AWS on production applications using the SDK. Also, for the purposes of this sample, please make sure your policy allows a client ID of `test-*` to connect or use `--client_id <client ID here>` to send the client ID your policy supports.
64
+
65
+
</details>
66
+
67
+
## How to run
68
+
69
+
To Run this sample from the `samples\mqtt` folder, use the following command:
70
+
71
+
```sh
72
+
# For Windows: replace 'python3' with 'python' and '/' with '\'
73
+
python3 mqtt5_aws_websocket.py \
74
+
--endpoint <AWS IoT endpoint> \
75
+
--signing-region <Signing region for websocket connection>
76
+
```
77
+
If you would like to see what optional arguments are available, use the `--help` argument:
78
+
```sh
79
+
# For Windows: replace 'python3' with 'python' and '/' with '\'
80
+
python3 mqtt5_aws_websocket.py --help
81
+
```
82
+
83
+
will result in the following output:
84
+
```
85
+
MQTT5 AWS Websocket Sample.
86
+
87
+
options:
88
+
-h, --help show this help message and exit
89
+
90
+
required arguments:
91
+
--endpoint IoT endpoint hostname (default: None)
92
+
--signing-region Signing region for websocket connection (default: None)
93
+
94
+
optional arguments:
95
+
--client-id Client ID (default: mqtt5-sample-809571c8)
96
+
--ca_file Path to optional CA bundle (PEM) (default: None)
97
+
--topic Topic (default: test/topic)
98
+
--message Message payload (default: Hello from mqtt5 sample)
99
+
--count Messages to publish (0 = infinite) (default: 5)
100
+
```
101
+
102
+
The sample will not run without the required arguments and will notify you of missing arguments.
103
+
104
+
## Additional Information
105
+
Additional help with the MQTT5 Client can be found in the [MQTT5 Userguide](../../documents/MQTT5_Userguide.md). This guide will provide more details on MQTT5 [operations](../../documents/MQTT5_Userguide.md#optional-keyword-arguments), [lifecycle events](../../documents/MQTT5_Userguide.md#lifecycle-events), [connection methods](../../documents/MQTT5_Userguide.md#connecting-to-aws-iot-core), and other useful information.
0 commit comments