1. 程式人生 > >Extend AWS DeepLens to Send SMS Notifications with AWS Lambda

Extend AWS DeepLens to Send SMS Notifications with AWS Lambda

AWS DeepLens is a deep learning enabled developer toolkit with a video camera. It enables you to develop machine learning skills using hands-on computer vision tutorials, pre-built models and allows you to extend them.

This blog post explains how to extend the local functionality of DeepLens with cloud functionality using the AWS IoT Rule Engine and a Lambda function. The simple functionality that we describe here is to send an SMS notification to your phone number after you see a hot dog with your DeepLens device. We expect more advanced users to extend this functionality to include other AWS Cloud services such as

Amazon Elasticsearch Service (build a dashboard and search interface for all objects and faces detected with timeline and frames), Amazon Kinesis Analytics (build anomaly detection models on the number of people walking in front of your store), Amazon Rekognition (use celebrity recognition and face search API to identify VIPs around you), and many others.

Here is a diagram that shows the flow of the data in the system from the object in front of the camera all the way to the mobile device in your pocket.

Create Your Lambda Function

First, you’ll create an AWS Lambda function that will run in the cloud and filter the messages that are coming from your DeepLens device for ones with high enough (>0.5) probability for a hot dog. During this process you will also create a rule in the AWS IoT rule engine to get messages from the Lambda function that you deployed to the device using AWS Greengrass.

  • On the AWS Lambda console go to“Create Function.”
  • Filter the Blueprints with “iot-button-email” and choose it as your blueprint template.
  • Give your Lambda function a name. For example “Hotdog_Notifier.”
  • Keep the “Create a new Role from template(s)” value in the Role field.
  • Give your new role a name. For example, “Hotdog_Notifier_Role.”
  • Add in the Policy Templates the policy for “SNS Publish policy.”
  • In the “aws-iot” section switch to use “Custom IoT Rule”
    • Choose “Create a new rule.”
  • Give it a name (for example, “search_hotdogs”) and a description.
  • In the Rule query statement put the SELECT query: Select Hotdog from ‘/$aws/deeplens/KJHFD-DKJO87-LJLKD/inference’. This query can catch messages from the DeepLens device in the following JSON format:  { "Hotdog" : 0.5438 }
  • Enable the Trigger in the checkbox that follows.
  • We will modify the code of the Lambda function in the next step.
  • Change the environment parameters from “email” to “phone_number”, and put your phone number as the Value. Please note that the phone number format should include the international country code (for example, for US +15555555555). You can read more on the international support for SMS in AWS SNS FAQ:  https://aws.amazon.com/sns/faqs/#sms-related-questions
  • Choose the “Create Function” button.
  • Switch to the “Configuration” of the Lambda function that you just created. You can find configuration tab on the left (configuration, triggers, and monitoring)
  • In the Lambda function code we can remove all the helper functions that are needed for a usual SNS subscription, such as findExistingSubscription, createSubscriptioncreateTopic.  Remove all the code until ‘use strict’. We will also modify the code to directly send the SMS:
    'use strict';
    
    /**
     * This is a sample Lambda function that sends an SMS Notification When your
     * Deep Lens device detects a Hot Dog
     * 
     * Follow these steps to complete the configuration of your function:
     *
     * Update the phone number environment variable with your phone number.
     */
    
    const AWS = require('aws-sdk');
    
    const phone_number = process.env.phone_number;
    const SNS = new AWS.SNS({ apiVersion: '2010-03-31' });
    
    exports.handler = (event, context, callback) => {
        console.log('Received event:', event);
    
        // publish message
        const params = {
            Message: `Your DeepLens device just identified a Hot Dog. Congratulations!`,
            PhoneNumber: phone_number
        };
        if (event.Hotdog > 0.5)
            SNS.publish(params, callback);
    };
  • Choose “Save.”. You can test the Lambda function from this screen as well, but we will test it through the IoT rule engine now, to simulate the flow of messages from the DeepLens device.

Test Your Configuration

  • In the IoT console select the “Test” option.
  • Choose Publish to a Topic and Publish to the topic you defined in your Rule above the following message { "Hotdog": 0.68725 }.
  • You should receive an SMS notification with the message: “Your DeepLens device just….” that you defined in your Lambda function.
  • Time to show your DeepLens device some objects and a hot dog. Good Luck!
  • If you don’t get messages when a hot dog is presented to the device, please go back to the diagram on top and verify that you aligned the values according to the colors, and that you provided the right phone number with the country code.

Conclusion

Amazon DeepLens is designed as an open platform for education and innovation, and we expect developers to come with many different ideas to use it to solve real life problems. From analyzing people walking around a store to automatically open the garage door to your car, or alerting you when tables in your restaurant are dirty or customers are asking for a service. This is only a small sample of systems you can build with AWS DeepLens using extensions similar to the simple one in this blog post.

Additional Reading

About the Author

Guy Ernest is a principal solutions architect in Amazon AI. He has the exciting opportunity to help shape and deliver on a strategy to build mind share and broad use of Amazon’s cloud computing platform for AI, machine learning and deep learning use cases. In his spare time, he enjoys spending time with his wife and family, gathering embarrassing stories, to share in talks about Amazon and the future of AI.

相關推薦

Extend AWS DeepLens to Send SMS Notifications with AWS Lambda

AWS DeepLens is a deep learning enabled developer toolkit with a video camera. It enables you to develop machine learning skills using hands-on co

Use AWS DeepLens to give Amazon Alexa the power to detect objects via Alexa skills

People are using Alexa for all types of activities in their homes, such as checking their bank balances, ordering pizza, or simply listening to th

Warning: Unable to send packet: Error with PF_PACKET send() [11]: Message too long (errno = 90)

今天在使用tcpreplay重放流量時,發現有的資料包沒有傳送成功: Warning: Unable to send packet: Error with PF_PACKET send() [215]: Message too long (errno = 90) Warn

How to Build an AWS DeepLens Project with Amazon SageMaker

Amazon Web Services is Hiring. Amazon Web Services (AWS) is a dynamic, growing business unit within Amazon.com. We are currently hiring So

How to send an SMS in Node.js via SMPP Gateway

How to send an SMS in Node.js via SMPP GatewayIntroductionSMPP (Short Message Peer-to-Peer) is a protocol used by the telecommunications industry. It excha

How to Build Serverless Vue Applications with AWS Amplify

You can also implement serverless AWS AppSync GraphQL APIs, Lambda functions, analytics, hosting, VR / AR scenes & more using the Amplify CLI & lib

The right way to manage secrets with AWS · Segment Blog

The way companies manage application secrets is critical. Even today, improper secrets management has resulted in an astonishing number of high profile bre

Deploy your own TensorFlow object detection model to AWS DeepLens

In this blog post, we’ll show you how to deploy a TensorFlow object detection model to AWS DeepLens. This enables AWS DeepLens to perform real-tim

Encrypting messages published to Amazon SNS with AWS KMS

Amazon Simple Notification Service (Amazon SNS) is a fully managed pub/sub messaging service for decoupling event-driven microservices, distribute

How to replace tape backup with a virtual tape library in the AWS Cloud

Tape media management, media costs, 3rd party offsite contracts and the sheer volume of data growth makes tape backup challenging in any org

How to Send Fanout Event Notifications

Now that you have created the topic with Amazon SNS, you will create Amazon SQS queues that will subscribe to the topic. When

How to Send Live Video to AWS Elemental MediaStore

In this blog post, I’ll describe how to send live HLS streams to AWS Elemental MediaStore. AWS Elemental MediaStore is an AWS storage serv

Configuring Cognito User Pools to Communicate with AWS IoT Core

AWS IoT Core supports certificate-based mutual authentication, custom authorizers, and Amazon Cognito Identity as way to authenticate requests to

Spring Boot使用RabbitMQ出現詭異異常:Failed to send reply with payload 'OK',Cannot determine ReplyTo message

今天專案中出現一個詭異的異常:org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception at org.sprin

Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key

Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are a great way to ensure your users re-engage with your

exchange 2013 error:5.7.1 Client does not have permissions to send as this sender

exchange2013 self權限看了幾個文章,都是寫的exchange2010的報錯,有點過時了,我寫下exchange2013遇到該問題的排查首先排除服務器的問題和用戶本地配置的問題。對比法:服務器是否有問題?其他賬戶是否有問題?本地環境下其他賬戶是否有問題?均排除,那麽問題就在賬號上了。查看該賬號在

微信企業號報agent only allow to send text

微信 企業號 報錯 {"errcode":60011,"errmsg":"no privilege to access\/modify contact\/party\/agent "} ,主要是沒有權限訪問或修改人員的信息等,研究後,其實只要將紅圈部分的通訊錄權限開通好,就可以了。{"errc

attempt to create delete event with null entity

system nag -c 16px ren host java lang eat SSH框架刪除單條數據不會報錯,一條以上數據回報: java.lang.IllegalArgumentException: attempt to create delete event wi

How to create own operator with python in mxnet?

處理 需要 調用父類 rgs rop 數據類型 賦值 創建 recipe 繼承CustomOp 定義操作符,重寫前向後向方法,此時可以通過_init__ 方法傳遞需要用到的參數 1 class LossLayer(mxnet.operator.CustomOp):

[React] Refactor a Stateful List Component to a Functional Component with React PowerPlug

code body col init onclick str pan from push In this lesson we‘ll look at React PowerPlug‘s <List /> component by refactoring a nor