diff --git a/samples/mqtt/websocket_connect/README.md b/samples/mqtt/websocket_connect/README.md index bd990058e..d89c01ff1 100644 --- a/samples/mqtt/websocket_connect/README.md +++ b/samples/mqtt/websocket_connect/README.md @@ -12,7 +12,6 @@ then you will need to replace part of the sample (connection\_setup function) wi * [Websocket Connect/custom auth](./README_custom_auth.md) * [Websocket Connect/username and password](./README_username_password.md) -* [Websocket Connect/proxy](./README_proxy.md) * [Websocket Connect/static credentials](./README_static_credentials.md) 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. @@ -48,7 +47,13 @@ For this sample, using Websockets will attempt to fetch the AWS credentials to a ## How to run -To run the websocket connect use the following command: +To use a proxy server which is optional pass the following arguments + +Optional parameters: +``` +--proxy_host +--proxy_port +``` ``` sh ./websocket-connect --endpoint --signing_region diff --git a/samples/mqtt/websocket_connect/README_custom_auth.md b/samples/mqtt/websocket_connect/README_custom_auth.md index 2c051cd05..e2eee3f79 100644 --- a/samples/mqtt/websocket_connect/README_custom_auth.md +++ b/samples/mqtt/websocket_connect/README_custom_auth.md @@ -2,17 +2,22 @@ [**Return to main sample list**](../../README.md) -This sample makes an MQTT connection via Websockets and then disconnects. -On startup, the device connects to the server via Websockets then disconnects right after. -This sample demonstrates connecting via custom auth authorizer username, -password and tokens +This sample makes an MQTT connection and connects through a Custom Authorizer. +On startup, the device connects to the server and then disconnects. +This sample is for reference on connecting using a Custom Authorizer. +Using a Custom Authorizer allows you to perform your own authorization using an AWS Lambda function. +See Custom Authorizer for more information. +You will need to setup your Custom Authorizer so that the lambda function returns a policy document. +See this page on the documentation for more details and example return result. +You can customize this lambda function as needed for your application to provide your own security measures based on the needs of your application. +Your IoT Core Thing's Policy 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. If you want to use simple or custom auth (or static creds, or basic auth, etc) instead, then you will need to replace part of the sample (connection\_setup function) with a code snippet we provided in its corresponding readme. * [Websocket Connect/simple_auth](./README.md) * [Websocket Connect/username and password](./README_username_password.md) -* [Websocket Connect/proxy](./README_proxy.md) * [Websocket Connect/static credentials](./README_static_credentials.md) 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. diff --git a/samples/mqtt/websocket_connect/README_proxy.md b/samples/mqtt/websocket_connect/README_proxy.md deleted file mode 100644 index 6b17e6498..000000000 --- a/samples/mqtt/websocket_connect/README_proxy.md +++ /dev/null @@ -1,108 +0,0 @@ -# Websocket Connect with Proxy - -[**Return to main sample list**](../../README.md) - -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 using a proxy. -This sample demonstrates conneting via Websockets using a proxy serverb. - -If you want to use simple or custom auth (or static creds, or basic auth, etc) instead, -then you will need to replace part of the sample (connection\_setup function) with a code snippet we provided in its corresponding readme. - -* [Websocket Connect/simple_auth](./README.md) -* [Websocket Connect/custom auth](./README_custom_auth.md) -* [Websocket Connect/username and password](./README_username_password.md) -* [Websocket Connect/static credentials](./README_static_credentials.md) - -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. - -
-(see sample policy) -
-{
-  "Version": "2012-10-17",
-  "Statement": [
-    {
-      "Effect": "Allow",
-      "Action": [
-        "iot:Connect"
-      ],
-      "Resource": [
-        "arn:aws:iot:region:account:client/test-*"
-      ]
-    }
-  ]
-}
-
- -Replace with the following with the data from your AWS account: -* ``: 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`. -* ``: 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. - -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 ` to send the client ID your policy supports. - -For this sample, using Websockets will attempt to fetch the AWS credentials to authorize the connection from a proxy server. - -
- -
- (code snipet to replace the connection_setup function) -
 
-void connection_setup(int argc, char *argv[], ApiHandle &apiHandle, Utils::cmdData &cmdData,
-             Aws::Iot::MqttClientConnectionConfigBuilder &clientConfigBuilder)
-{
-    Utils::cmdData cmdData = Utils::parseSampleInputWebsocketConnect(argc, argv, &apiHandle);
-
-    std::shared_ptr provider = nullptr;
-    Aws::Crt::Auth::CredentialsProviderChainDefaultConfig defaultConfig;
-    provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderChainDefault(defaultConfig);
-    if (!provider)
-    {
-        fprintf(stderr, "Failure to create credentials provider!\n");
-        exit(-1);
-    }
-    Aws::Iot::WebsocketConfig config(cmdData.input_signingRegion, provider);
-    clientConfigBuilder = Aws::Iot::MqttClientConnectionConfigBuilder(config);
-    if (cmdData.input_ca != "")
-    {
-        clientConfigBuilder.WithCertificateAuthority(cmdData.input_ca.c_str());
-    }
-    if (cmdData.input_proxyHost == "")
-    {
-        fprintf(stderr, "proxy address missing!\n");
-        exit(-1);
-    }
-    Aws::Crt::Http::HttpClientConnectionProxyOptions proxyOptions;
-    proxyOptions.HostName = cmdData.input_proxyHost;
-    proxyOptions.Port = static_cast(cmdData.input_proxyPort);
-    proxyOptions.AuthType = Aws::Crt::Http::AwsHttpProxyAuthenticationType::None;
-    clientConfigBuilder.WithHttpProxyOptions(proxyOptions);
-
-    if (cmdData.input_port != 0)
-    {
-        clientConfigBuilder.WithPortOverride(static_cast(cmdData.input_port));
-    }
-    clientConfigBuilder.WithEndpoint(cmdData.input_endpoint);
-}
-
-
-
- -## How to run - -Options for connecting through an HTTP proxy -``` ---proxy_host ---proxy_port -``` - -To run the websocket connect use the following command: - -``` sh -./websocket-connect --endpoint --signing_region --proxy_host --proxy_port -``` - - - - diff --git a/samples/mqtt/websocket_connect/README_static_credentials.md b/samples/mqtt/websocket_connect/README_static_credentials.md index a7f9df9a8..32b2b3864 100644 --- a/samples/mqtt/websocket_connect/README_static_credentials.md +++ b/samples/mqtt/websocket_connect/README_static_credentials.md @@ -2,8 +2,6 @@ [**Return to main sample list**](../../README.md) -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. - This sample makes an MQTT connection via Websockets and then disconnects. On startup, the device connects to the server via Websockets then disconnects right after. This sample demonstrates connecting via static credentials. @@ -13,7 +11,6 @@ then you will need to replace part of the sample (connection\_setup function) wi * [Websocket Connect/simple_auth](./README.md) * [Websocket Connect/username and password](./README_username_password.md) -* [Websocket Connect/proxy](./README_proxy.md) * [Websocket Connect/custom auth](./README_custom_auth.md) 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. diff --git a/samples/mqtt/websocket_connect/README_username_password.md b/samples/mqtt/websocket_connect/README_username_password.md deleted file mode 100644 index bec84f202..000000000 --- a/samples/mqtt/websocket_connect/README_username_password.md +++ /dev/null @@ -1,86 +0,0 @@ -# Websocket Connect Username and Password - -[**Return to main sample list**](../../README.md) - -This sample makes an MQTT connection via Websockets and then disconnects. -On startup, the device connects to the server via Websockets then disconnects right after. -This sample demonstrates connecting via custom auth authorizer username and -password. - -* [Websocket Connect/simple_auth](./README.md) -* [Websocket Connect/custom auth](./README_custom_auth.md) -* [Websocket Connect/proxy](./README_proxy.md) -* [Websocket Connect/static credentials](./README_static_credentials.md) - -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. - -
-(see sample policy) -
-{
-  "Version": "2012-10-17",
-  "Statement": [
-    {
-      "Effect": "Allow",
-      "Action": [
-        "iot:Connect"
-      ],
-      "Resource": [
-        "arn:aws:iot:region:account:client/test-*"
-      ]
-    }
-  ]
-}
-
- -Replace with the following with the data from your AWS account: -* ``: 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`. -* ``: 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. - -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 ` to send the client ID your policy supports. - -For this sample, using Websockets will attempt to connect using username and password. - -
- -
- (code snipet to replace similar section) -
 
-void connection_setup(int argc, char *argv[], ApiHandle &apiHandle, Utils::cmdData &cmdData,
-    Aws::Iot::MqttClientConnectionConfigBuilder &clientConfigBuilder)
-{
-    cmdData = Utils::parseSampleInputCustomAuthorizerConnect(argc, argv, &apiHandle);
-
-    // Create the MQTT builder and populate it with data from cmdData.
-    Aws::Crt::Auth::CredentialsProviderChainDefaultConfig defaultConfig;
-    std::shared_ptr provider =
-        Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderChainDefault(defaultConfig);
-    Aws::Iot::WebsocketConfig websocketConfig((cmdData.input_signingRegion), provider);
-
-    clientConfigBuilder = Aws::Iot::MqttClientConnectionConfigBuilder(websocketConfig);
-    clientConfigBuilder.WithEndpoint((cmdData.input_endpoint));
-    clientConfigBuilder.WithCustomAuthorizer(
-        (cmdData.input_customAuthUsername),
-        (cmdData.input_customAuthorizerName),
-        (cmdData.input_customAuthorizerSignature),
-        (cmdData.input_customAuthPassword));
-}
-
-
-
- -## How to run -Options for custom auth -``` ---custom_auth_username ---custom_auth_authorizer_name ---custom_auth_authorizer_signature ---custom_auth_password -``` - -To run the websocket connect use the following command: - -``` sh -./websocket-connect --endpoint --signing_region -``` -