aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

Where to get device instantiation params from? #177

Closed rococtz closed 6 years ago

rococtz commented 6 years ago

I am trying to setup a simple device client in the browser following this example in the README file:

var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
   keyPath: <YourPrivateKeyPath>,
  certPath: <YourCertificatePath>,
    caPath: <YourRootCACertificatePath>,
  clientId: <YourUniqueClientIdentifier>,
      host: <YourCustomEndpoint>
});

I have created a thing, a type and associated them with a police in my AWS IoT console, but where do I get the <...> information from? Also, since it's going to be part of a front-end application, is it safe to put it here?

fengsongAWS commented 6 years ago

Hi @rococtz , You are right that using cert and root CA in browser environment is not recommended. Instead, you can use websocket connection which only requires IAM credentials. https://github.com/aws/aws-iot-device-sdk-js#connections

rococtz commented 6 years ago

Thank you for the info @fengsongAWS , but I still can't get it to work. I created a custom authorizer in my AWS IoT console and then I instantiate the client like this:

client = awsIot.device({
    protocol: 'wss-custom-auth',
    host: 'my-host.us-east-2.amazonaws.com',
    customAuthHeaders: {
      'X-Amz-CustomAuthorizer-Name': '<name-of-mycustom-authorizer-in-aws-iot>',
      'X-Amz-CustomAuthorizer-Signature': '< ???? >',
      '<token-key-name-I-created>': '<some-generated-token>'
    }
  });

Any idea what goes into X-Amz-CustomAuthorizer-Signature ?

fengsongAWS commented 6 years ago

Hi @rococtz , That filed is used for customer who wants to use custom auth feature. If you do not want to set up custom auth, you can simply ignore that. For your web browser, you can setup coginito and websocket connection using IAM credentials.

fengsongAWS commented 6 years ago

Please open another thread if you still have questions.