AWS iot mqtt Lambda function unique id

Hello,

I finaly got the mqtt demo running and now i am able to send JSON messages from the esp32 to a lambda function. In the future the code will be running on many devices. So to be able to differentiate the devices, i’ll need an unique id (For DB related stuff). I know looking through the cloudwatch logs in AWSIotLogsV2 that there is a lot more information that i simply not able to recieve in my lamda function (through the sql Rule). In theory i only the ‘clientId’ or the ‘Thing_name’

One way i found is to make the sql rule like this:

$aws/things/+/topic/subtopic

I’ve tried, didn’t get it work but i also find a bit inapporiate.
An other way i can think of, is just to make sure that the mqtt message has an unique id inside.

If anyone has an idea what i can try or share how you done it, please do.

Thanks

Is this something the Lambda forum could help with? All Posts - Forums

Thank you, That link guided me to a good source of information.

In the end i found i can add the following to the rule.
clientId() as clientId which gives you the thing name.
Now you can use the thing name to differentiate the devices.

@GoldDiggerTh, just want to make it clear that client Id is not necessarily equivalent to the thing name and client Id is not necessarily a unique Id. The broker requires all connected devices to have a unique client Id, but a device can change its client Id and essentially spoof another device if the other device is disconnected. Fortunately, a device cannot connect to the broker using a thing name that is different from the one it’s registered as and has an accompanying certificate to securely connect. To ensure that a device uses the same client Id as it’s registered thing name, you need to enforce it with your device policy. This will ensure that the client Id is unique.

You can read more about it here: Security best practices in AWS IoT Core - AWS IoT Core