© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The configuration steps required to create the “Hello World” application and test a device’s ability to communicate
across the IoT network includes the following:
•
Creating and Testing the Lambda Function
•
•
•
•
Testing your “Hello World” Application
8.2 Creating and Testing the Lambda Function
The lambda function is used to process device messages, after they have been processed by the IoT Rules Engine.
The IoT Rules Engine processes these messages using a configured destination rule.
To create the lambda function to process device messages processed by the destination rule, follow these steps:
1.
Go to the AWS Lambda console (console.aws.amazon.com/lambda).
2.
Click on
Functions
in the navigation pane.
3.
Click on
Create function
.
4.
Select
Author from scratch.
Under
Basic information
, enter the function name “
sailboatdecoder
” and
choose
Runtime Node.js 12.x.
from the
Runtime
drop-down menu.
5.
Click on
Create function
.
6.
Navigate to
<<provide your github repository URL>>
and copy the code for the lambda function.
7.
Under
Function code
, paste the copied code into the editor under the
index.js
tab.
8.
Once the code has been pasted, choose
Deploy
to deploy the lambda code.
9.
Click on the
Permissions
tab of the lambda function
10.
Change the
Lambda Role Policy
permission by following these steps:
a.
Under
Execution role
, click on the hyperlink under
Role name
.
b.
On the
Permissions
tab, find the policy name and click on it.
c.
Choose
Edit policy
, and choose the
JSON
tab.
d.
Append the following to the
Statement
section of the policy to allow publishing to AWS IoT:
,
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"*"
]
}
e.
Choose
Review Policy
, then
Save changes
.
To test the lambda function, use the following steps to create a test event:
1.
In the drop-down for
Select a test event
, choose
Configure test events
.
2.
Enter a name for the test event under
Event name
.
3.
Paste the following sample payload in the area under
Event name
:
{
"MessageId": "55d122ab-6355-2233-9874-ff47c5222108",
"WirelessDeviceId": "65d128ab-90dd-4668-9556-fe47c589610b",
"PayloadData": "zA0LYgHpAX//f/8=",
"WirelessMetadata":
{
"LoRaWAN":