Create the Lambda Function

Note

In this tutorial, we will be setting up resources in the AWS Oregon region (us-west-2). Before continuing, ensure that the region dropdown in the top right of your screen says Oregon.

To process data from the device, we will use a Kinesis stream and a Lambda function.

Below is the code of the lambda function that will be used to process the data being written to the Kinesis stream. You will cut and paste the source code in this function into the Lambda console.

  1. Open the Lambda console page by clicking Services > Lambda
  2. Press the blue Get Started Now button.
_images/new_lambda_function.png
  1. Enter the name of the fuction and an optional description.

    _images/lambda_function_name.png
  2. Cut and paste the source code from the Javascript file at the URL listed above. Substitute the string “[TABLE_NAME]” with the name of the device table that was created in the CloudFormation stack.

    _images/lambda_edit_code.png
  3. Select the role that was created from the CloudFormation stack in the previous step. It should have a name like [StackName]-DeviceExecutionRole-XXXXX

    _images/lambda_select_role.png
  4. Press Create. The function has now been created.

    _images/lambda_function_created.png
  5. Add an event source to the function by selecting “Actions->Add Event Source”

  6. Choose the Kinesis stream created by the CloudFormation stack as the event source.

    _images/lambda_add_event_source.jpg
  7. Press Submit. You should now see the Kinesis stream show up in the “Event Source” list beneath the function.

    _images/lambda_event_source_list.png

Congratulations!! You have now successfully set up your AWS backend infrastructure.