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
AWS IoT Core Custom Authentication allows you to use a lambda to gate access to IoT Core resources. For this authentication method,
119
95
you must supply an additional configuration structure containing fields relevant to AWS IoT Core Custom Authentication.
@@ -129,7 +105,7 @@ If your custom authenticator does not use signing, you don't specify anything re
129
105
auth_password=<Binary data value of the password field to be passed to the authorizer lambda>)
130
106
```
131
107
132
-
If your custom authorizer uses signing, you must specify the three signed token properties as well. The token signature must be the URI-encoding of the base64 encoding of the digital signature of the token value via the private key associated with the public key that was registered with the custom authorizer. It is your responsibility to URI-encode the token signature.
108
+
If your custom authorizer uses signing, you must specify the three signed token properties as well. It is your responsibility to URI-encode the auth_username, auth_authorizer_name, and auth_token_key_name parameters.
133
109
134
110
```python
135
111
# other builder configurations can be added using **kwargs in the builder
@@ -182,6 +158,30 @@ A MQTT5 direct connection can be made using a PKCS12 file rather than using a PE
182
158
183
159
**Note**: Currently, TLS integration withPKCS#12 is only available on MacOS devices.
184
160
161
+
#### **MQTT over Websockets with Sigv4 authentication**
162
+
Sigv4-based authentication requires a credentials provider capable of sourcing valid AWS credentials. Sourced credentials
163
+
will sign the websocket upgrade request made by the client while connecting. The default credentials provider chain supported by
164
+
the SDKis capable of resolving credentials in a variety of environments according to a chain of priorities:
#### **MQTT over Websockets with Cognito authentication**
186
186
187
187
A MQTT5 websocket connection can be made using Cognito to authenticate rather than the AWS credentials located on the device or via key and certificate. Instead, Cognito can authenticate the connection using a valid Cognito identity ID. This requires a valid Cognito identity ID, which can be retrieved from a Cognito identity pool. A Cognito identity pool can be created from the AWS console.
@@ -211,7 +211,7 @@ To create a MQTT5 builder configured for this connection, see the following code
211
211
212
212
**Note**: A Cognito identity ID is different from a Cognito identity pool ID and trying to connect with a Cognito identity pool ID will not work. If you are unable to connect, make sure you are passing a Cognito identity ID rather than a Cognito identity pool ID.
213
213
214
-
####**HTTP Proxy**
214
+
### **Adding an HTTP Proxy**
215
215
No matter what your connection transport or authentication method is, you may connect through an HTTP proxy
216
216
by adding the http_proxy_options keyword argument to the builder:
First, install the `aws-iot-devices-sdk-python-v2` with following the instructions from [Installation](../README.md#Installation).
28
35
29
-
Each sample README has instructions on how to run each sample with the same name as the sample itself. For example, the [PubSub README](./pubsub.md) is `pubsub.md` and it can be run with the following:
36
+
Each sample README has instructions on how to run each sample with the same name as the sample itself. For example, the [MQTT5 PubSub README](./mqtt5_pubsub.md) is `mqtt5_pubsub.md` and it can be run with the following:
30
37
31
38
```sh
32
39
# For Windows: replace 'python3' with 'python' and '/' with '\'
33
-
python3 pubsub.py --endpoint <endpoint> --cert <path to certificate> --key <path to private key>
40
+
python3 mqtt5_pubsub.py --endpoint <endpoint> --cert <path to certificate> --key <path to private key>
34
41
```
35
42
36
43
### Sample Help
@@ -39,7 +46,7 @@ All samples will show their options by passing in `--help`. For example:
39
46
40
47
```sh
41
48
# For Windows: replace 'python3' with 'python' and '/' with '\'
42
-
python3 pubsub.py --help
49
+
python3 mqtt5_pubsub.py --help
43
50
```
44
51
45
52
Which 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.
@@ -48,9 +55,9 @@ Which will result in output showing all of the options that can be passed in at
48
55
49
56
To enable logging in the samples, you need to pass the `--verbosity` as an additional argument. `--verbosity` controls the level of logging shown. `--verbosity` can be set to `Trace`, `Debug`, `Info`, `Warn`, `Error`, `Fatal`, or `None`.
50
57
51
-
For example, to run [PubSub](./pubsub/README.md) sample with logging you could use the following:
58
+
For example, to run [MQTT5 PubSub](./mqtt5_pubsub.md) sample with logging you could use the following:
52
59
53
60
```sh
54
61
# For Windows: replace 'python3' with 'python' and '/' with '\'
## **Alternate Connection Configuration Methods supported by AWS IoT Core**
76
+
### **Optional Keyword Arguments**
77
+
All lifecycle events and the callback for publishes received by the MQTT5 Client should be added to the builder on creation of the Client. A full list of accepted arguments can be found in the API guide.
78
+
79
+
*[Direct MQTT with X509-based mutual TLS](#direct-mqtt-with-x509-based-mutual-tls)
80
+
*[Direct MQTT with Custom Authentication](./mqtt5_custom_authorizer_connect.md)
81
+
*[Direct MQTT with PKCS11 Method](./mqtt5_pkcs11_connect.md)
82
+
*[Direct MQTT with PKCS12 Method](#direct-mqtt-with-pkcs12-method)
83
+
*[MQTT over Websockets with Sigv4 authentication](#mqtt-over-websockets-with-sigv4-authentication)
84
+
*[MQTT over Websockets with Cognito authentication](#mqtt-over-websockets-with-cognito-authentication)
85
+
### HTTP Proxy
86
+
*[Adding an HTTP Proxy](#adding-an-http-proxy)
87
+
88
+
#### **Direct MQTT with X509-based mutual TLS**
89
+
For X509 based mutual TLS, you can create a client where the certificate and private key are configured by path:
90
+
91
+
```python
92
+
# X.509 based certificate file
93
+
cert_file_path ="<certificate file path>"
94
+
# PKCS#1 or PKCS#8 PEM encoded private key file
95
+
pri_key_filepath ="<private key file path>"
96
+
97
+
# other builder configurations can be added using **kwargs in the builder
98
+
99
+
# Create an MQTT5 Client using mqtt5_client_builder
100
+
client = mqtt5_client_builder.mtls_from_path(
101
+
endpoint="<account-specific endpoint>",
102
+
cert_filepath=certificate_file_path,
103
+
pri_key_filepath=private_key_filePath))
104
+
```
105
+
106
+
#### **Direct MQTT with PKCS12 Method**
107
+
108
+
A MQTT5 direct connection can be made using a PKCS12 file rather than using a PEM encoded private key. To create a MQTT5 builder configured for this connection, see the following code:
109
+
110
+
```python
111
+
# other builder configurations can be added using **kwargs in the builder
112
+
113
+
client = mqtt5_client_builder.mtls_with_pkcs12(
114
+
pkcs12_filepath="<PKCS12 file path>,
115
+
pkcs12_password="<PKCS12 password>
116
+
endpoint="<account-specific endpoint>")
117
+
```
118
+
119
+
**Note**: Currently, TLS integration with PKCS#12 is only available on MacOS devices.
120
+
121
+
#### **MQTT over Websockets with Sigv4 authentication**
122
+
Sigv4-based authentication requires a credentials provider capable of sourcing valid AWS credentials. Sourced credentials
123
+
will sign the websocket upgrade request made by the client while connecting. The default credentials provider chain supported by
124
+
the SDK is capable of resolving credentials in a variety of environments according to a chain of priorities:
125
+
126
+
```Environment -> Profile (local file system) -> STS Web Identity -> IMDS (ec2) or ECS```
127
+
128
+
If the default credentials provider chain and built-in AWS region extraction logic are sufficient, you do not need to specify
#### **MQTT over Websockets with Cognito authentication**
146
+
147
+
A MQTT5 websocket connection can be made using Cognito to authenticate rather than the AWS credentials located on the device or via key and certificate. Instead, Cognito can authenticate the connection using a valid Cognito identity ID. This requires a valid Cognito identity ID, which can be retrieved from a Cognito identity pool. A Cognito identity pool can be created from the AWS console.
148
+
149
+
To create a MQTT5 builder configured for this connection, see the following code:
150
+
151
+
```python
152
+
# The signing region. e.x.: 'us-east-1'
153
+
signing_region ="<signing region>"
154
+
155
+
# See https://docs.aws.amazon.com/general/latest/gr/cognito_identity.html for Cognito endpoints
**Note**: A Cognito identity ID is different from a Cognito identity pool ID and trying to connect with a Cognito identity pool ID will not work. If you are unable to connect, make sure you are passing a Cognito identity ID rather than a Cognito identity pool ID.
173
+
174
+
## **Adding an HTTP Proxy**
175
+
No matter what your connection transport or authentication method is, you may connect through an HTTP proxy
176
+
by adding the http_proxy_options keyword argument to the builder:
177
+
178
+
```python
179
+
http_proxy_options = http.HttpProxyOptions(
180
+
host_name="<proxy host>",
181
+
port=<proxy port>)
182
+
183
+
# Create an MQTT5 Client using mqtt5_client_builder with proxy options as keyword argument
184
+
client = mqtt5_client_builder.mtls_from_path(
185
+
endpoint="<account-specific endpoint>",
186
+
cert_filepath="<certificate file path>",
187
+
pri_key_filepath="<private key file path>",
188
+
http_proxy_options= http_proxy_options))
189
+
```
190
+
191
+
SDK Proxy support also includes support for basic authentication and TLS-to-proxy. SDK proxy support does not include any additional
192
+
proxy authentication methods (kerberos, NTLM, etc...) nor does it include non-HTTP proxies (SOCKS5, for example).
0 commit comments