Need to create a skill that stores data in a table?
In this video, I'll show you that you can use a database for free in your skill.
Let's talk about what DynamoDB is and how we can use it in our skills.
What is DynamoDB?
But first, let's start with what DynamoDB is.
Amazon DynamoDB is a serverless ( • O Que É Serverless? ) NoSQL key-value database designed to run high-performance applications at any scale.
DynamoDB offers built-in security, continuous backups, automated multi-regional replication, in-memory caching, and data export tools.
The interesting thing here is that DynamoDB was developed by Amazon. They created this database for their own use and then made it available as a service to their customers.
DynamoDB Components
In terms of structure, DynamoDB has similarities to relational databases. Tables: As in other databases, DynamoDB stores data in tables.
Items: Each table contains zero or more items. An item is a group of attributes uniquely identifiable among all other items.
Attributes: Each item is composed of one or more attributes. An attribute is a fundamental data element, something that doesn't need to be divided. They are similar to columns in relational databases.
Nested Attributes: DynamoDB supports nested attributes up to 32 levels deep.
Secondary Indexes: Allows querying data in the table using an alternate key, in addition to queries based on the primary key.
Primary Key: Can be a simple primary key, of one attribute, or a composite key of two attributes.
But unlike relational databases, tables may or may not have schemas. Each item can have its own distinct attributes.
Using DynamoDB in Skills
Until recently, the only way to persist data in an Alexa Hosted skill using the free tier we receive from AWS was by using S3.
And we've already talked about S3 here ( • O Que É Amazon S3? ).
Well, a few months ago Amazon started providing a table in DynamoDB along with the other resources provisioned in an Alexa Hosted skill.
When you create this type of skill, in addition to Lambda, other AWS services are provisioned at the free tier, such as S3 ( • O Que É Amazon S3? ), CloudWatch ( • O Que É CloudWatch? ), and DynamoDB.
This means you don't need to do anything. When you create a skill, DynamoDB provisioning is automatic.
You can access DynamoDB through the corresponding icon in the toolbar of the Code tab in the Developer Console.
Clicking on it will open another browser tab in DynamoDB:
Accessing DynamoDB Through the Skill
ASK has an adapter to manipulate data in DynamoDB.
There's nothing new here for those who already develop for the web.
Include a package in the solution, import it into the code, and use the package's methods to create a connection and access the database.
Here's a high-level step-by-step guide on how to do this access within your skill's code.
1. Add the DynamoDB access package dependency to the package.json file.
2. In the index.js file, add the code. Import the ask persistence adapter.
3. Include the SessionEndedRequestHandler. Do not override other request handlers.
4. Create a handler to save attributes.
5. Create a handler to read attributes.
If you found this interesting and want me to talk more about how to use DynamoDB in skill code, leave a comment below.
Final Words
What is DynamoDB? Amazon DynamoDB is a fully managed NoSQL database service from AWS that provides fast and predictable performance with built-in scalability.
Unlike a relational database, interactions with DynamoDB are stateless, meaning applications don't need to maintain persistent network connections.
When creating an Alexa Hosted skill, a DynamoDB table is provisioned to persist data, which is part of the AWS free tier.
That's all for today!
And if you want to learn more about programming, keep following me!
If you liked this video, give it a like and subscribe to the channel. Don't forget to turn on notifications to receive an alert when new videos are published.
Until next time!
Follow me here ⤵⤵
💻 Blog: https://celsokitamura.com.br
💻 Instagram: / celsokitamura
🎥 Youtube: / celsokitamura
🔵 Facebook: / celsokitamura
#WhatIsDynamoDB
#IAmAnAppDev