简体   繁体   中英

AWS IoT Event Java Class for Lambda

  • I am invoking an AWS Lambda function from AWS IoT.
  • I am writing my Lambda function in Java
  • According to this link http://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html?shortFooter=true , it says: Rules engine — Provides message processing and integration with other AWS services. You can use a SQL-based language to select data from message payloads, process the data, and send the data to other services, such as Amazon S3, Amazon DynamoDB, and AWS Lambda. You can also use the message broker to republish messages to other subscribers.
  • So this link clearly states that my lambda function need not subscribe to it and that it can get the message payload data.
  • How the handler function works is you pass the input and output type, input type in my case is the information I want to send from my IoT topic which would be something like for example "IoTEvent" (similar to S3Event, SNSEvent, etc).
  • On searching all the event classes available from https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events , I cannot find the event class for IoT.
  • I would like to have information about the class which supports all the methods to get the payload.

There is no general IoTEvent. The payload will be sent to lambda in a JSON format. So create a POJO class in your lambda with the same variables as the payload. Use your POJO class as the input for your Lambda function. AWS Lambda will automatically map the JSON payload to your POJO class. Check this link for using POJOs for Lambda input. https://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-pojo.html

This is the only way I have been able to make this work with Java Lambda. Just make sure the JSON and the POJO match up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM