question

newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 avatar image
newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 asked ·

Dynamodb in an Alexa hosted skill - Can anyone give me a concrete python example please? Thanks!

Hi! I am trying to build some toy learning apps by modifying the example code you get in the examples from the Alexa console. Python is preferred and appreciated.


For the life of me I can't get any of my code to work. I am now getting all kind of weird access errors, exactly like a previous question here. However he was doing something slightly different.


Can anyone give me concrete code to share with all here that A) Creates a dynamodb and auto creates the table B) store something in it C) read it back D) update it. Just a really simple example that has the includes as well. Googling for answers is not as much fun as getting code to work... :-) Thank you in advance. Yes I am trying to get persistence working, working on a learning app. No I don't want to use S3, I need something like a db/redis

P.S in a previous question here it was suggested that this tutorial will walk you through how to adapt it from S3 to DynamoDB.

https://forums.developer.amazon.com/questions/216242/how-can-i-use-dynamodbadapter-with-an-alexa-hosted.html

@barry@amazon : it mentions twice that if you ever do this properly you should use DynamoDB but nowhere does it actually cover how it is instanced and used instead of the S3. This is driving me nuts. :-)

import boto3
from ask_sdk_dynamodb.adapter import DynamoDbAdapter

srvcResource = boto3.resource('dynamodb')

seb = DynamoDbAdapter(table_name="mythopoeic",create_table=True,dynamodb_resource=srvcResource)

or should I go the whole hog and just do it from the console manually (create db and use keys) like suggested here?

https://stackoverflow.com/questions/56714239/how-can-you-use-dynamodb-persistence-adapter-in-pyhon-sdk


Or forget it and use Flask-Ask on my laptop as a development endpoint?

alexa skills kitdynamodbask sdkhosted skill
10 |2000 characters needed characters left characters exceeded

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

newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 avatar image
newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 answered ·

@barry@amazon - any chance you can help here? You answered a previous similar question. Thanks.

10 |2000 characters needed characters left characters exceeded

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

Rokas avatar image
Rokas answered ·

I would use sdk, it will be much easier to work with than building everything yourself using flask. I use node, so it is a little bit harder to help you, but had you taken a look at example like this: here, based on this tutorial? They explain basics, how to persist session attributes in dynamo db.

1 comment
10 |2000 characters needed characters left characters exceeded

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

@RokasV - Thank you so much. Actually if you can share your thoughts in Node.js that would be fine, it will give me an analogy to code in Python. I would really be grateful. :-) Also have you seen Flask-ask? It does a tremendous amount in the framework, I thought it would really help increase the pace of development when I finally get there but the cost of deployment will be exponentially higher compared to Lambda.


https://blog.craftworkz.co/flask-ask-a-tutorial-on-a-simple-and-easy-way-to-build-complex-alexa-skills-426a6b3ff8bc?gi=5eef2cf8ec90


0 Likes 0 ·
newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 avatar image
newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 answered ·

Repasting due to this software hiding follow up comments:


@RokasV - Thank you so much. Actually if you can share your thoughts in Node.js that would be fine, it will give me an analogy to code in Python. I would really be grateful. :-) Also have you seen Flask-ask? It does a tremendous amount in the framework, I thought it would really help increase the pace of development when I finally get there but the cost of deployment will be exponentially higher compared to Lambda.


https://blog.craftworkz.co/flask-ask-a-tutorial-on-a-simple-and-easy-way-to-build-complex-alexa-skills-426a6b3ff8bc?gi=5eef2cf8ec90


10 |2000 characters needed characters left characters exceeded

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

Jason@Amazon avatar image
Jason@Amazon answered ·
5 comments
10 |2000 characters needed characters left characters exceeded

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

@Jason@amazon - Many thanks, I had already found it and used it to create the code above. Now I can't understand why it still doesnt work and I get similar permissions errors as the person before but I thought since this is a hosted lambda code that the permissions are autogenerated.


Could I ask that an Amazonian Alexa Python expert code an example and post it? Please? Pretty Please? :-) It should take 15 minutes right? :-) Clearly it's just a syntax problem or similar. I'm a noob.


I'm setting up a local Pyflask setup as described but would like to get the hosted version working. Thanks.

0 Likes 0 ·
Jason@Amazon avatar image Jason@Amazon ♦ newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 ·

Going off of what RokasV has mentioned, if you want to use hosted skills, you need to set up permissions to allow your skill to use the resources in your own AWS account (in this case your DynamoDB):

https://developer.amazon.com/en-US/docs/alexa/hosted-skills/build-a-skill-end-to-end-using-an-alexa-hosted-skill.html#personal

Note that there is a Python example too so you can use to to ensure you have the correct permissions set up.

1 Like 1 ·
Rokas avatar image Rokas newuser-09ed25b3-2bd6-4dd4-bd61-25381e2e0c61 ·

If you are getting permissions issue, maybe you didn't give lambda dynamoDB permissions. You can do it, by creating IAM role. You can try following this tutorial: here.

0 Likes 0 ·

@Jason@amazon - Thank you for your answer, I'll check that post out and try creating a permission. It seems to be that but was never mentioned before for use with the console templates. Appreciated :-) Please don't close this as I'd like to make sure it works and I'll post a concrete solution.

0 Likes 0 ·