How to get AWS IOT client id?

Ildar picture Ildar · Oct 8, 2017 · Viewed 9.1k times · Source

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?

Answer

Keivan picture Keivan · May 28, 2018

Whenever you define a thing in AWS IoT, a unique identifier will be assigned to your device in your AWS IoT account. By default it is same as the name of thing(defaultClientId) and you can use it for connect to the AWS IoT broker. You can retrieve informaiotn about your thing by using AWS SDKs(or name of your device). For example by using Python SDK:

import boto3
client = boto3.client('iot')
response = client.describe_thing(
    thingName = [Name of your thing in AWS IoT]
)

print(response)