0
votes

I have a AWS Lambda which publishes data to a AWS IOT topic A and waits for the result, which will be published to a different topic B.

I was wondering how to get this data from topic B when the thing publishes it to the already running lambda.

I was not able to find any equivalent to get_thing_shadow for a particular topic https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iot-data.html#id4

Eg:

Lambda1 -> IOT Topic A -> Thing

Lambda1 waiting

Thing -> IOT Topic B

Lambda1 reads from Topic B and updates say DB and dies.

I was wondering how this can be done.

For some reasons we are unable to use IOT Shadow anymore.

Current architecture:

Lambda1 -> IOT Shadow Desired -> Thing

Lambda1 -> waits for 5 sec

Lambda1 -> reads IOT Shadow Reported -> success or failure

If failure Lambda1 -> resets IOT Desired to old state -> exists

2

2 Answers

0
votes

It is not possible to configure IoT to send the new message to the "already running" Lambda. It will always trigger a new invocation of the Lambda function. Isn't the previous state already in the IoT Shadow Update Failed message? Can't you just use that data in the new invocation to do whatever DB updates or whatever else you need?

0
votes

AWS sdk for lambda(e.g. boto3 for python) does not support subscribing topic. It only support publishing topic.

If you want to subscribe topic, You must use device sdk (ref. https://docs.aws.amazon.com/iot/latest/developerguide/iot-sdks.html )

And then, You can publish and subscribe by device sdk in lambda.

If you don't want to use device sdk, you have to use redis or dynamoDB like below.

device publish response message -> AWS IoT Rule trigger some action(e.g. write to DB ) -> lambda polling DB.