Make alexa say something from a Lambda function - aws-lambda

I am using https://github.com/hortinstein/node-dash-button to record some activity in my home. For example, I want to record time I go to bed every day. I am running node-dash-button application in my home network on a raspberry pi. When dash button is pressed I am making an entry in DynamoDB.
Now the problem is, there is no feedback when entry is made in DynamoDB. I have an Amazon Echo Dot. Is it possible that I trigger a Lambda function based on the entry I make in DynamoDB which eventually send a voice command to my Echo dot. For example: Entry of time 2200 Hours recorded. What I am looking for is a particular feature which I can use and develop on, any pointers or names will be helpful.
--
Thanks

As if now Alexa doesn't support Push Notification which is what needed in this case. Without waking up alexa, it is not possible to get any acknowledgement.

There currently isn't a way to get Alexa to activate when you create a dynamodb record, however you could create a skill to read you the time when the record was made through a lambda function.
If you are ok with not using Alexa to get your notifications, you could use AWS' SNS service and a lambda function to push a notification to your phone when a record is made. Service is relatively cheap if there aren't many users.
related docs:
https://aws.amazon.com/sns/getting-started/
http://docs.aws.amazon.com/lambda/latest/dg/with-sns-example.html

Related

How to design notification system that sends real-time alerts created by users

I've been thinking about how to design a system that supports user created scheduled alerts. My problem is once the alerts are created and inserted into a database, I don't know what the best way to go about scheduling those alerts. Polling the database to see which alerts need to go out next doesn't seem entirely right to me.
What are some ways this could be handled on a scale where say a million users could create their own custom alerts like change baby diaper at 3pm everyday?
This problem is very suitable for cloud platforms. For example, you could use GCP Cloud Scheduler to invoke a cloud function when the alert is supposed to be sent out. The cloud function then calls some API to alert the user.
If cloud platforms are not an option, you could have your application spawn a new thread when an alert is created, and sleep that thread for a certain duration. When it wakes up, it sends the alert. Less elegant and less scalable than the first solution, but it would still work.

Is it possible to connect alexa output to amazon SQS

I have created a alexa smart home function and want to run it asynchronously so plan to use amazon sqs (Simple que service) functionality. I connected amazon sqs trigger output to lambda function and successfully able to send message from sqs to lambda. Now need to connect the alexa to sqs input. When i try to use sqs arn in alexa developer console it does not support it. Is there any way to solve this or will alexa support only lambda function for invocation.
The alexa skill is for smart home service to control switches (Turn on/off), so when try to control the multiple switches because of synchronous nature execution of lambda it turns on switches one after the other. I need to control them at single shot so need asynchronous execution for lambda where requests need to execute without waiting for the response.
Thanks in advance for answers.
It will not work as SQS works asynchronus and just reply that message was put there. But Alexa needs a valid JSON response with speech tag and so on immediately and SQS is not able to fulfill this.
What you could do:
Alexa -> Lambda (new) -> SQS - Lambda
In your new created lambda you could give a valid reply to Alexa and put a message in SQS.
AWS Lambda can work asynchronously. You can have a bunch of back-end processes all working as they need to, triggering various Lambdas as needed.
But the exchange with Alexa opens a session to your backend, sends its request, and the full response is expected to end that session. That response may have directives to download other content to incorporate into the response, like a sound file or lazy loading a list in APL. But it is expecting a full response.
If you go through the basic Cake Time tutorial for building Alexa skills, they actually use async-await for some APIs because that response has to be complete before it's sent.
There are some async APIs like reminders and proactive events, but they're NOT conversational. They're unique one-way messages.
The real questions are why do you feel you need to do it this way and what are you optimizing for by queuing?

Best way to schedule one-time events in serverless environments

Example use case
Send the user a notification 2 hours after signup.
Options considered
setTimeout(() => { /* send notification */ }, 2*60*60*1000); is not an option in serverless environments since the function terminates after execution (so it has to be stateless).
CloudWatch events can schedule lambda invocations using cron expressions - but this was designed for repetitive invocations (there's a limit of 100 rules/region).
I have not seen scheduling options in AWS SNS/SQS or GCP Pub/Sub. Are there alternatives with scheduling?
I want to avoid (if possible) setting up a dedicated message broker (overkill) or stateful/non-serverless instance - is there a serverless way to do this?
I can queue the events in a database and invoke a lambda function every minute to poll the database for events to execute in that minute... is there a more elegant solution?
Use AWS Step functions, they are like serverless functions that don't have the 15 minute limit like AWS Lambda does. You can design a workflow in AWS step that integrates with API Gateway, Lambda and SNS to send email and text notifications as follows:
Create a REST API via API gateway that will invoke a Lambda function passing in for example, the destination address (email, phone #) of the SNS notification, when it should be sent, notification method (e.g. email, text, etc.).
The Lambda function on invocation will invoke the Step function passing in the data (Lambda is needed because API Gateway currently can't invoke Step functions directly).
The Step function is basically a workflow, you can define states for waiting (like waiting for the specified time to send the notification e.g. 30 seconds), and states for invoking other Lambda functions that can use SNS to send out an email and/or text notifications.
A rudimentary example is provided by AWS w/ their Task Timer example.
Things are coming on GCP for doing this, but not very soon. Thereby, today, the solution is to poll a database.
You can to that with Datastore/firestore with the execution datetime indexed (to prevent to read all the documents each minute). But be careful of traffic spike, you could create hotspot.
You can use Cloud Scheduler on Google Cloud Platform. As is is stated in the official documentation :
Cloud Scheduler is a fully managed enterprise-grade cron job scheduler. It allows you to schedule virtually any job, including batch, big data jobs, cloud infrastructure operations, and more. You can automate everything, including retries in case of failure to reduce manual toil and intervention. Cloud Scheduler even acts as a single pane of glass, allowing you to manage all your automation tasks from one place.
Here you can check a quickstart for using it with Pub/Sub and Cloud Functions.

How to make AWS Lambda wait for a shadow updated topic

My desired flow is:
ask my iot device to do something using AVS sdk
aws lambda triggered and update the device shadow
iot device triggered based on the shadow topic: delta and do something locally. Publish the status to shadow when done doing something
aws lambda sends voice feedback to my iot device to tell users the reported status
I am stuck in point 4 since I dont know how to trigger AVS(ASK)'s speech response only after the topic is updated "within the same lambda triggered by AVS (as mentioned in point 1 and 2).
You don't want lambda to wait.
I heard from a wise man onetime,
A long lived Lambda = EC2 Instance
Either create an iot rule to trigger a lambda on specific topics,
or,
create an api endpoint to update the topic and trigger it from the client.

Push and pull with Parse

So what I need is a kind of a push and pull web service mechanism; Certain devices will be sending data to my parse backend and some others should be able to receive the newly added data as it's being added. Think of it as a restaurant environment where customers send their order via their phones and the restaurant manager receives the orders on his pc real time.
I know I can use push notifications but I want to target specific users (in this case the manager alone). I guess I can have a specific push notification channel in which only the manager is added, but I am not sure if I can send proper json data in bulk or just simple strings. Maybe there's a smarter way of going about it.
Any suggestions?
Many thanks,
Polis
You can use the Parse Cloud for this purposes. So certain devices (you can differentiate in cloud or in client side) can call the cloud method. The called cloud method can make http request to your server (manager pc real time). From now on your server side can deliver coming message to your manager in real time. In this solution, I assume that you have your own server for web users (like manager) and mobile application for client user (customers).
Hope this can give you an idea. Regards.
You can use Push notification for this purpose. In my opinion that would be your best option.
When registering for push notification on client side, you can set a column owner to user pointer. Now when sending push notification from one user to another you can query the Installation class for other user's pointer. You can send push notification either from client side or writing cloud code for afterSave trigger. Cloud code is a better option.
The downside of this approach is that if other user did not allow push notifications then this would fail. The second user would still be able to get the data when they open the app, but won't get push notifications.
***I built a chat app using this approach on Parse.com
You don't need a complicated channel setup, before you save your installation, do a line like this:
[installation setObject:[PFUser currentUser] forKey:#"owner"];
[installation saveInBackground]; // ... completion or whatever
Then, just query:
PFQuery *installationQuery = [PFInstallation query];
[installationQuery whereKey:#"owner" equal:userImLookingFor];
Then, it's like PFPush w/ query or something.
(I'm typing from memory, so some of these might need to be slightly tweaked)

Resources