11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ASK SDK V2 for Node.js - PersistenceAdapter の使い方

Last updated at Posted at 2018-08-03

SDK V2では、Skillインスタンスを作成する2つのSkillBuilderが含まれています。

  1. Custom Skill Builder
  2. Standard Skill Builder

Standard Skill Builder を使いたい場合は、デフォルトでDynamoDBPersistentAdopterが利用できるが、ask-sdk-coreパッケージを使いたい場合や、Custom Skill Builderを使いたい場合は、別途ask-sdk-dynamodb-persistence-adapterパッケージをロードして、使用することになる。

ask-sdk-dynamodb-persistence-adapterパッケージは、AWS DynamoDBを使ってPersistenceAdapterを実装するものです。

#1. ask-sdk-dynamodb-persistence-adapterパッケージをダウンロードする

npm install --save ask-sdk-core
npm install --save ask-sdk-dynamodb-persistence-adapter

#2. DyanamoDBAdopterのインスタンスを生成する。


const Adapter = require('ask-sdk-dynamodb-persistence-adapter');

const config = {tableName: 'hogehoge_table', // <= DynamoDBのテーブル名
                createTable: true}; // <= テーブルを自動生成する場合true (ただし権限が必要)
const DynamoDBAdapter = new Adapter.DynamoDbPersistenceAdapter(config);

#3. Custom Skill BuilderにAdopterを登録する


const skillBuilder = Alexa.SkillBuilders.custom(); // <= Custom Skill Builder

exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    HelpIntentHandler,
    StopIntentHandler,
    SessionEndedRequestHandler
  )
  .withPersistenceAdapter(DynamoDBAdapter) // <= ここを追加
  .addErrorHandlers(ErrorHandler)
  .lambda();

これで、Standard Skill Builder と同様に属性の永続化処理が自動的に行われる。

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?