LoginSignup
5
3

More than 5 years have passed since last update.

アレクサのスキルでDynamoDB

Posted at

備忘録ようです。

設定

  1. IAMにいって、左の画面からロールを洗濯
  2. lambdaと入力し、作成したロール選択
  3. ポリシーのアタッチを押して、「AmazonDynamoDBFullAccess」のチェックをオンにして画面右下の[ポリシーのアタッチ]ボタンをクリックする。

export.handler内でテーブルの定義

ここでDynamoDB内で定義されていないテーブルなら自動で作るみたい

exports.handler = function(event, context, callback) {
  var alexa = Alexa.handler(event, context);

  alexa.dynamoDBTableName = 'TestTable'; // TestTableテーブルを定義

  alexa.registerHandlers(handlers, synastriesHandlers); // 既存のハンドラに加えてステートハンドラ(後半で定義)も登録
  alexa.execute();
};

保存

this.attributes["test"] = "test"

スクリーンショット 2017-12-07 22.02.29.png
DynamoDBでこんな感じに見れる

取得

発話によってインテントを分けているので、条件分岐で取得するのは必要になると思われる

if (this.attributes['sign']) {
      var sign = this.attributes['sign']; // DynamoDBから読み込んだデータを参照
} else {
  this.emit('AMAZON.HelpIntent');
}
5
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
5
3