Search code examples
amazon-web-servicesaws-iot

How to get AWS IOT client id?


I use AWS IoT for real-time update in my web application. The application connects to AWS IoT using aws-iot-device-sdk:

const client = awsIot.device({
    region: awsConfig.region,
    protocol: 'wss',
    accessKeyId: <accessKey>,
    secretKey: <secretKey>,
    sessionToken: <sessionToken>,
    port: 443,
    host: <iotEndpoint>
});

client.on('connect', res => {
    // ok
});

I want to use AWS Lifecycle Events. For example:

$aws/events/presence/connected/{clientId}

How to get MQTT client id?


Solution

  • If you look at the documentation, you will see that clientId is one of the parameters you can supply to the device() method. You should be generating a client ID for each connected device that is unique to your application (i.e. unique to your AWS IoT account).