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
* WebSocket Connection methods
* Merge readmes into one file
* Fix local links
* Fix local links
* Fix local links
* add connection_setup to websocket_connect
* add return
Copy file name to clipboardExpand all lines: samples/websocket_connect.md
+150-5Lines changed: 150 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,19 @@
1
1
# Websocket Connect
2
2
3
3
[**Return to main sample list**](./README.md)
4
+
If you want to use custom auth (or static creds, or basic auth, etc) instead,
5
+
then you will need to replace part of the sample (connection\_setup function) with a code snippet we provided in its corresponding readme.
4
6
5
-
This sample makes an MQTT connection via Websockets and then disconnects. On startup, the device connects to the server via Websockets and then disconnects right after. This sample is for reference on connecting via Websockets. This sample demonstrates the most straightforward way to connect via Websockets by querying the AWS credentials for the connection from the device's environment variables or local files.
7
+
*[Websocket Connection Using Custom Authentication](#websocket-connection-using-custom-authentication)
8
+
*[Websocket Connection Using Static Credentials](#websocket-connection-using-custom-authentication)
6
9
7
-
Your IoT Core Thing's [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect. Below is a sample policy that can be used on your IoT Core Thing that will allow this sample to run as intended.
10
+
This sample makes an MQTT connection via Websockets and then disconnects.
11
+
On startup, the device connects to the server via Websockets and then disconnects right after.
12
+
This sample is for reference on connecting via Websockets.
13
+
This sample demonstrates the most straightforward way to connect via Websockets by querying the AWS credentials for the connection from the device's environment variables or local files.
14
+
15
+
Your IoT Core Thing's [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect.
16
+
Below is a sample policy that can be used on your IoT Core Thing that will allow this sample to run as intended.
8
17
9
18
<details>
10
19
<summary>(see sample policy)</summary>
@@ -29,17 +38,153 @@ Replace with the following with the data from your AWS account:
29
38
*`<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`.
30
39
*`<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.
31
40
32
-
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.
41
+
Note that in a real application, you may want to avoid the use of wildcards in your ClientID or use them selectively.
42
+
Please follow best practices when working with AWS on production applications using the SDK.
43
+
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.
33
44
34
-
For this sample, using Websockets will attempt to fetch the AWS credentials to authorize the connection from your environment variables or local files. See the [authorizing direct AWS](https://docs.aws.amazon.com/iot/latest/developerguide/authorizing-direct-aws.html) page for documentation on how to get the AWS credentials, which then you can set to the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` environment variables.
45
+
For this sample, using Websockets will attempt to fetch the AWS credentials to authorize the connection from your environment variables or local files.
46
+
See the [authorizing direct AWS](https://docs.aws.amazon.com/iot/latest/developerguide/authorizing-direct-aws.html) page for documentation on how to get the AWS credentials, which then you can set to the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` environment variables.
35
47
36
48
</details>
37
49
38
50
## How to run
39
51
52
+
Optional parameters:
53
+
```
54
+
--proxy_host <str>
55
+
--proxy_port <int>
56
+
```
40
57
To run the websocket connect from the `samples` folder, use the following command:
41
58
42
59
```sh
43
60
# For Windows: replace 'python3' with 'python' and '/' with '\'
# Websocket Connection Using Custom Authentication
66
+
67
+
This sample makes an MQTT connection and connects through a [Custom Authorizer](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html).
68
+
On startup, the device connects to the server and then disconnects.
69
+
This sample is for reference on connecting using a Custom Authorizer.
70
+
Using a Custom Authorizer allows you to perform your own authorization using an AWS Lambda function.
71
+
See [Custom Authorizer](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html) for more information.
72
+
You will need to setup your Custom Authorizer so that the lambda function returns a policy document.
73
+
See [this page on the documentation](https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html) for more details and example return result.
74
+
You can customize this lambda function as needed for your application to provide your own security measures based on the needs of your application.
75
+
Your IoT Core Thing's [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect.
76
+
Below is a sample policy that can be used on your IoT Core Thing that will allow this sample to run as intended.
77
+
78
+
If you want to use simple or custom auth (or static creds, or basic auth, etc) instead,
79
+
then you will need to replace part of the sample (connection\_setup function) with a code snippet we provided in its corresponding readme.
80
+
81
+
<details>
82
+
<summary> (code snipet to replace the similar function)</summary>
83
+
<prelanguage="python">
84
+
<code>
85
+
def connection_setup():
86
+
# cmdData is the arguments/input from the command line placed into a single struct for
87
+
# use in this sample. This handles all of the command line parsing, validating, etc.
88
+
# See the Utils/CommandLineUtils for more information.
0 commit comments