With what context is data sent from a Lambda to AWS IoT core?

243 views Asked by At

We can use a lambda function to connect to AWS IoT Greengrass core and publish messages. For device to receieve msg published by lambda, 2 things need to be satisfied: 1) There needs to be a subscription to the lambda in the greengrass (with appropriate topic) and 2) the subscriber's code does a .subscribe to that topic. Lambda example:

import greengrasssdk
import json

# Greengrass client to publish to
client = greengrasssdk.client('iot-data')

# Executed on every messages received from the subscription
def lambda_handler(event, context):
  
  client.publish(topic='lab/greengrass/telemetry', payload=json.dumps(event))
  
  return

Here the message is published in context of the Lambda and not a device. Similarly if I had to send msg from lambda to AWS IoT Core, the msg doesn't go from context of lambda as a device, but lambda itself.

However, we could also publish message via Lambda that represents a thing to AWS IoT Core or other device, and for this we will need to pass in credentials (thing credentials) to identify the Lambda as a device (thing).

Have I understood this right?

1

There are 1 answers

2
Dr Things On BEST ANSWER

Not quite. I think you are missing the concept of Subscriptions in greengrass here!

You can make the Lambdas and Devices communicate among themselves or with the AWS IoT Core without having to configure lambda as a Thing.

Checkout the Subscriptions section in your Greengrass core where it will allow you to create subscriptions between one lambda/device/AWS IoT Core to the other.

Ofcourse for onboarding a device to greengrass you need to register it as a thing and download credentials for it and place it as required. But that's not the case to have a lambda publish messages to other lambdas or devices!