question

KJ avatar image
KJ asked

Could someone post a working example of a Java Lambda function class

Cannot get a class to work based on the documentation in the skills kit webpage. Using Eclipse and the AWS Plugin to upload the class. I am unsure if the "handler method" is required for these classes, or its role, as it isn't mentioned in the skills kit. Thanks.
alexa skills kitdebugging
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
There was a lot of interest in this at the Amazon Dev Day. David Isbitski confirmed it could be done, but said there were no examples of it. His suggestion was to take a Javascript example, and just kind of massage it into Java. I haven't had a chance to look at this yet, though.
10 |5000

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

The Stig avatar image
The Stig answered
David told us the same thing at the dev day I attended.
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
I just tried now. I think I know what needs to be done, but when I right click my project, select Amazon Web Services -> Upload function to AWS Lambda... nothing happens. A dialog is supposed to come up. That's where I'm stuck. Is that where you are stuck?
1 comment
10 |5000

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

yes,I right click my project and noting happens.

0 Likes 0 ·
Sergey avatar image
Sergey answered
I was one of the people running around and asking everyone how to make Java work in Lambda for Alexa. Dave introduced me to Ricardo from AWS team, who mentioned that upload from Eclipse plugin to Lambda doesn't work for Java. To make it Java work with Lambda, you essentially need to either write a handler, which takes a JSON in the POST deserialized using standard Lambda JSON deserializer (assuming that's possible), checks the contents (e.g. if the call for Intent, Launch, etc.) and calls appropriate function. Essentially, you need to reimplement a Speechlet class, which is part of the SDK (it can be easily decompiled from the .class). If the built-in Lambda deserializer doesn't cut it for JSON sent by Alexa servers, then you you need to take input from the Stream. Both options are described here --> http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html Dave mentioned that Amazon is working on providing examples for AWS Lambda and it will be coming. It's not there yet, because this is all super new. Java support in Lambda is 2 weeks old, public Alexa API is 1 week old.
10 |5000

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

KJ avatar image
KJ answered
Gents, I have also tried both the Eclipse AWS Plugin's "Upload Function to AWS Lambda" technique, and packaging the class(es) into a JAR file (deployment package) as per the "Creating a .jar Deployment Package Using Maven and Eclipse IDE (Java)" on the AWS documentation pages. Using the required "handler" function, I have been able to retrieve the Alexa requests as Objects, but cannot successfully get them into the proper subclass of SpeechletRequest, even though I got close with some of the SpeechletRequestEnvelope.fromJson() methods...hence I have been unable to get calls to go through to the Speechlet methods. I have not tried to implement my own request builders. Sounds like Amazon is working on making that connection go well. My only option is utilizing AWS Lambda, so I'd really love to see an update that actually supports this in Java.
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
Sergey! Good to see you here! >Both options are described here The handler is not my problem. The first one I wrote just returns a static JSON string from the example. I'll work on parsing later. What I don't understand is the packaging. That's the magic that happens when you use the non-working menu. Do you just zip up the .class files and upload them through the web UI? Do I have to include a manifest? How does it know which class is my handler? >It's not there yet, because this is all super new. Java support in Lambda is 2 weeks old, public Alexa API is 1 week old. Pfffft. Why post something that doesn't work? If they are going to do that, why aren't they updating the Alexa toolkit more frequently?
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
Sergey and KJ gave me enough clues, and I finally got this working tonight. I'll polish it up and then post it to https://github.com/jjaquinta/EchoProofOfConcepts tomorrow. Steps should end up being something like: 1) Create a java project 2) Create a lib dir, and dump in a bunch of jar files from the AlexAppKit 3) Create your speechlet 4) Instead of creating an extension of SpeechletServlet, I'll have a new SpeechletLambda to extend. 5) Export the zip file 6) Upload and go! I managed to convert one of my demo skills (Knock, Knock) to a lambda function with no code change. In a related note, I'm also thinking of modifying EchoSim so that you can give it your zip file and use it to test your function before uploading.
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
OK, I've added the sample to the EchoProofOfConcept project on GitHub. I've exported the project and posted it as a release here: https://github.com/jjaquinta/EchoProofOfConcepts/releases/tag/1.0.1 There's a readme with a step-by-step guide of what I did to get it to work.
10 |5000

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

KJ avatar image
KJ answered
jjaquinta - Just looked through your files on github and now I am anxious to try to get them to work from my end. Nice job implementing the handler function. Thanks for all the effort!
10 |5000

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

KJ avatar image
KJ answered
Jo - My AWS tools for eclipse do not work the same way you described in your HowTo - but after much arguing with AWS Lambda and Eclipse, I finally hand-jammed a zip file together with your described structure and got my Java Alexa Lambda function to run. Thanks again for the assist. KJ
10 |5000

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