Alexa and Kubernetes: MongoDB Persistence Adapter (II)
In this article, we will discuss Alexa and Kubernetes again and teach you how to create an Alexa Persistence Adapter to connect to MongoDB.
Join the DZone community and get the full member experience.Join For Free
ASK SDK MongoDB Persistence Adapter package contains an implementation of persistence adapter in Core SDK
ask-sdk-core , based on AWS SDK.
What Is the ASK SDK MongoDB Persistence Adapter?
The ASK SDK v2 for Node.js is an open-source Alexa CustomSkill Development Kit. ASK SDK v2 for Node.js makes it easier for you to build highly engaging skills by allowing you to spend more time on implementing features and less on writing boilerplate code.
The ASK SDK MongoDB Persistence Adapter package is an add-on package for the core SDK
ask-sdk-core and, thus, has peer dependency of the core SDK package. From within your NPM project, run the following commands in the terminal to install them:
npm install --save ask-sdk-mongodb-persistence-adapter
Usage and Getting Started
You can find all the documentation here.
How to create an instance of
First, pass the MongoDB URL connection as a parameter:
Finally, we have to add this new adapter to the
SkillBuilders object with the method
Now, check the
MongoDBPersistenceAdapter full specification here.
Also, check the
PartitionKeyGenerator full specification here.
Usage With TypeScript
The ASK SDK MongoDB Persistence Adapter package for Node.js bundles TypeScript definition files for use in TypeScript projects and supports tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public API.
Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of the requirements below:
- Use TypeScript v2.x.
- Include the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
npm install --save-dev @types/node
To use the TypeScript definition files within a Node.js project, simply import ask-sdk-mongodb-persistence-adapter.
In a TypeScript file:
For bug reports, feature requests, and questions, we would like to hear about it. Search the existing issues and try to make sure your problem doesn’t already exist before opening a new issue. It’s helpful if you include the version of the SDK, Node.js, or browser environment and OS you’re using. Please include a stack trace and reduced repro case when appropriate too.
This Adapter is distributed under the Apache License, Version 2.0. See LICENSE for more information.
As you can see, with just 4 lines of code, we can transform an Alexa Skill using AWS Lambda into an Express app, all thanks to the Amazon Alexa team and its fabulous adapter.
I hope this example project is useful to you.
You can find the code here.
That’s all folks! Happy coding!
Opinions expressed by DZone contributors are their own.