AWS Lambda Functions


#1

Hi,

I have a concept, but I have not been able to get it working on the NXPRapidIOT. I want to have an AWS DynamoDB table with three keys “Red”, “Green”, “Blue” all having boolean values. When I change the value of one of these keys, say “Red = True” in the AWSDynamoDB table, I want the RapidIOT RGB led to shine red. I am struggling in trying to find the correct (or just fuctional) way to allow asynchronous communications from AWS DynamoDB to the RapidIOT. I do not want to have the RapidIOT periodically polling the AWSDyanmoDB table to check for changes.
Here is the most recent description of my attempt…
I am trying to figure out how to allow an AWS DynamoDB trigger event act as an input to the NXPRapidIOT. My thought is that I would create an AWS Lambda function that would be executed by a DynamoDB trigger. The Lambda function would send a signal through a cloud element to the RapidIOT that indicating there has been a change to the database. The RapidIOT would then use cloud elements and AWSDynamoDB elements to pull the new data in from AWS.
Am I going down the wrong path in my approach?
Thank you!


#2

Hi @sealamb. Yes this a valid path you can take to sending down the data to your Rapid IoT. Have you considered using the Cloud Command Element after responding to a Lambda Element invocation?

https://developer.atmosphereiot.com/documents/elements/cloudcommandelement.html

Keep in mind, you will have to keep your mobile app open and connected to the Rapid IoT continuously while you are triggering your Lambda with every DynamoDB change.


#3

I am having a difficult time trying to understand Lambda Invocation and Triggering. Would you have any example projects using the Lambda Function, particulary in Invocation mode?

Maybe it is my understanding of Lambda Invocation that is wrong.

I have DynamoDB set up to trigger a Lambda function that sends me an email. That works well. What I am now trying to do is have Atmosphere recognize (asynchronously) that a particular Lambda Function has been triggered. Then a Cloud Command triggers a BLE event, which then triggers a toggle the on red led. Once I get that part working I think everything else will fall into place.

Thank you for your help!


#4

From what you are describing it sounds like you are looking to have your Atmosphere Project respond asynchronously to a Lambda invocation from outside of your project?

If this is the case, you can add a Cloud Event Element to your project, copy down the Element Name, generate an API token for your Atmosphere account, provision a device and record its thingUuid. This will allow you to then send an HTTP request with the API token in the header from within your Lambda function to the Atmosphere Device.

To configure your Cloud Event Element, see here
https://developer.atmosphereiot.com/documents/elements/cloudeventelement.html
The Cloud Event Element can lead into a BLE Characteristic Element in order to send the data contained in the Cloud Event back down to your embedded device.

Here’s how you can use the BLE Characteristic Element:
https://developer.atmosphereiot.com/documents/elements/blecharacteristicelement.html

For more information on generating an API token for your account, see here:
https://developer.atmosphereiot.com/documents/account/accountmanagement.html#api-tokens

Send a request from your Lambda to:
https://platform.atmosphereiot.com/user/thing/*thingUuid/admin/event/:elementName/:value

Where thingUuid is the provisioned device’s UUID.
The elementName is the name of the Cloud Event Element as defined in your Atmosphere Project.

Inside the Lambda function, send an HTTP request. The headers should contain api_auth_token as the header key with the actual API Token UUID as the header value.


#5

Thank you for these great details. I am slowly progressing and learning a lot!
Questions: I am thinking that I can check parial functionality by entering the “https://…” request in a browser, right? If so, I can test functionality before integrating it into a lambda function, which would give me confidence in knowing the API token is OK and any problems would be associated with my AWS setup.
The reason I ask this is because I have tried it and I get one of two responses… “forbidden” or “null”. I suspect “null” is a good sign that I have access through a webbrowser. Please correct me if I am wrong.
If this works through a web browser, I will be able to finalize my AtmoshphereIOT app and then make a lambda function in AWS (this means I will not be using a Lambda function within the AtmosphereIOT app at all since AWS will be sending an HTTP request) - Correct?


#6

@sealamb So a null response means you’ve successfully sent data to the Cloud Event. You will have to make sure your phone is connected to your embedded device, and that the device is running while it responds to Lambda invocations from outside of Atmosphere to fire off the rest of the connected elements in your project when the HTTP request is received by Atmosphere.