未加星标

AWS IoT Button, Lambda and Couchbase

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Getting Started with Serverless FaaS and AWS Lambda showshow to use a simple Java functionto store a JSON document to Couchbase using AWS Lambda. This blog buildsupon that and shows how an AWS IoT Button can be used as atrigger for that Lambda function.

By end of this blog, you’ll learn:

How to configure the AWS IoT Button Use the IoT Button astrigger for Lambda Function Test the IoT button

The overall flowwill be:


AWS IoT Button, Lambda and Couchbase

The IoT button click will invoke the HelloCouchbaseLambdaLambda function. This function is uses the Couchbase Java SDK to create a JSON document in Couchbase.

This blog is also playingcatch up with Collecting iBeacon Data with Couchbase and Raspberry Pi IoT Devices by Nic and The CouchCase by Matthew on their summer projects.One last blog will be published in this series. That will show how multiple AWS IoT buttons can be usedfor some fun.

Let’s get started!

Configure IoT Button

The fastest way to configure the IoT button is by using the mobile app for iOS or Android.


AWS IoT Button, Lambda and Couchbase
AWS IoT Button, Lambda and Couchbase

Seemore details about configuring IoT Button using mobile app .

Here are some snapshots from configuring button using the mobile app.

Bring up the app, click on + to start configuring a new button:


AWS IoT Button, Lambda and Couchbase

Enter the button’s serial number:


AWS IoT Button, Lambda and Couchbase

Register the button:


AWS IoT Button, Lambda and Couchbase

Configure the buttonwith a wifi network:


AWS IoT Button, Lambda and Couchbase

Upload all the certificates etc:


AWS IoT Button, Lambda and Couchbase

After this, the button is configured and ready to use. This blog skipped the part where a template Lambda Function is associated with the button click.

If a mobile appcannot be used then the button can be configured manually .

Use IoT Button as Trigger for Lambda Function

The aws lambda create-event-source-mapping CLI allows to create an event source for Lambda function. As of AWS CLI version 1.11.21 , only an Amazon Kinesis stream or an Amazon DynamoDB stream can be used. But for this blog, we’ll use the IoT button as a trigger. And this has to be configured using AWS Lambda Console .

IoT Button is only supported in a limited number of regions. For example, it is not supported in the us-west-1 region but us-west-2 region works.

The list ofregions not supported are greyed out in the following list:


AWS IoT Button, Lambda and Couchbase

Lambda Functioncan be triggered by several events.Lambda Function is invoked when any of theseevents occur. By default, no triggers are associated witha Lambda Function. For our HelloCouchbaseLambda function, these can be seen at us-west-2.console.aws.amazon.com/lambda/home?region=us-west-2#/functions/HelloCouchbaseLambda?tab=triggers .


AWS IoT Button, Lambda and Couchbase

Click on Add trigger to add a new trigger:


AWS IoT Button, Lambda and Couchbase

Select on the empty square to create a new trigger, and select AWS IoT :


AWS IoT Button, Lambda and Couchbase

Forthe button previously registered, get the serial number from us-west-2.console.aws.amazon.com/iotv2/home?region=us-west-2#/thinghub :


AWS IoT Button, Lambda and Couchbase

Specify the serial number of the button in the AWS IoT trigger:


AWS IoT Button, Lambda and Couchbase

Click on Submit to create the trigger:


AWS IoT Button, Lambda and Couchbase

And this confirms that the trigger has been added.

Test IoT Button

Before testing the button, let’s login to the Couchbase instance and verify the number of JSON documents in the bucket:


AWS IoT Button, Lambda and Couchbase

This can be verified at http://<EC2-IP-Address>:8091/index.html#sec=buckets . As expected, no documents exists in the bucket.

Press the button once, and refresh the page. It shows that one document is now stored in the bucket. This is verified in the Couchbase Web Console:


AWS IoT Button, Lambda and Couchbase

Click on Documents to see the complete list of documents:


AWS IoT Button, Lambda and Couchbase

Click on the document ID to see more details about the document:


AWS IoT Button, Lambda and Couchbase

Only the timestamp is stored in this JSON document.

Now, let’s update HelloCouchbaseLambda code to include request id in thedocument as well. This can be achieved by adding the following line of code in theJava class:

buttonDocument.setRequestId(context.getAwsRequestId());

A new deployment package can be built and uploaded using the following command:

mvn clean package;
aws lambda update-function-code
--function-name HelloCouchbaseLambda
--zip-file fileb:///Users/arungupta/workspaces/serverless/aws/hellocouchbase/hellocouchbase/target/hellocouchbase-1.0-SNAPSHOT.jar
--region us-west-2
--publish

Now clicking the button will update the number of documents. But the updated document will have an additional attribute populated as shown:


AWS IoT Button, Lambda and Couchbase

How are you going to take AWS IoT button and use it with Lambda and Couchbase? Let us know at Couchbase Forums .

References AWS IoTButton

本文数据库(综合)相关术语:系统安全软件

主题: JavaRaspberry PiAndroidiOS
分页:12
转载请注明
本文标题:AWS IoT Button, Lambda and Couchbase
本站链接:http://www.codesec.net/view/520263.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(63)