question

Will Strain avatar image
Will Strain asked

Lambda and Dynamo

Does anyone here have much experience with getting Lambda to work with DynamoDB? My commands run and don't produce an error but at the same time the data doesn't move. I think there might be a permissions error or something so I was just hoping someone here might know a thing or two. I am using javascript and the putitem and getitem commands. Thanks for any help.
alexa skills kitsubmission testing certification
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ross@Amazon avatar image
Ross@Amazon answered
Alexa Skills Kit samples can be found here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/using-the-alexa-skills-kit-samples-node. By following the included instructions you should be able to build these sample skills very quickly and easily. These examples will help you to better understand how Alexa skills should be created. The Score Keeper example illustrates reading and writing to a database using AWS DynamoDB, which is very easy to access from a Lambda function.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jjaquinta avatar image
jjaquinta answered
If you need a Java example, let me know. I got it working with Java. Had to have the right permissions, and right jar files. But worked fine once that was set up. Only issue is that it seems to take about 500-1200ms to do the Dynamo interaction. That's a fair chunk of your time budget for a lambda function.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Greg Crawford avatar image
Greg Crawford answered
If you don't see an error nor success callback from the putitem (or getitem) method, it probably means you are exiting the lambda function before the dynamodb call is completed. The call to putitem or getitem is asynchronous and will return control to your code immediately - you need to wait for the error/success callback. Make sure that any path that leads to context.done or context.succeed isn't called before the callback for putitem is handled. The Amazon sample code shows how to do this.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Frank Giuffrida avatar image
Frank Giuffrida answered
What do you mean by the "time budget" of a Lambda function? I presume that "throttling" occurs if you go into an infinite loop, and I that is what the timeout value is for. So far I see none of my lambda invocations "throttling" according to the monitor. But as far as budget goes, isn't Amazon happy to continue selling me time for a lambda function until I run out of credits.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jjaquinta avatar image
jjaquinta answered
Lambda functions have to be short and quick. That's what they were designed for. I found that if the function took more than either 500 or 5000 ms, it was dropped as incomplete. I can't remember the exact number. All I remember is that I had to restructure my code to optimize the number of Dynamo DB calls I made to keep within the cut off.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.