LoginSignup
3
5

More than 5 years have passed since last update.

Alexaのスキル開発中、Warning: Application ID is not set

Last updated at Posted at 2018-01-31

alexa.APP_ID を alexa.appIdに修正すれば解決

結論から言うと仕様が変わったようで、文字列をほんの少し修正するとWarningが消えました。
以下経緯と解説です。

スキルのデバッグ中にWarningを発見

Amazon EchoのAlexaのスキルの処理をAWS Lambdaに書きながらデバッグしていたところ、AWS ClowdWatch Management Consoleにいつの間にか以下のエラーが出ており気になったので調査しました。

2018-01-28T03:58:29.297Z    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx    Warning: Application ID is not set

アプリケーションIDがセットされていないとのことです。
今回AWS Lambdaの関数作成時に選択できる設計図であるalexa-skill-kit-sdk-factskillを選択して開発を始めましたが、どうも仕様に変更があったらしくこのままだとWarningになるようです。(スキルは一応ちゃんと動くので気づきにくい!)

どこがWarningの原因となっていたのか

alexa-skill-kit-sdk-factskillを選択して生成されるコードは以下のようになっていました。

index.js
// 一部不要なコメント等を省略しています
// 以下10行目〜15行目付近
'use strict';
const Alexa = require('alexa-sdk');
// 以下の行にスキルの`アプリケーション ID`を指定する必要があります(最初はundefinedですね)
const APP_ID = undefined;  // TODO replace with your app ID (OPTIONAL).

// 〜
// (中略)
// 〜

// 以下140目付近〜
exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    // 以下の行に上の方で設定したアプリケーションIDが入るようですね
    alexa.APP_ID = APP_ID;
    // To enable string internationalization (i18n) features, set a resources object.
    alexa.resources = languageStrings;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

alexa.APP_IDが現在は使われていないようです。
以下のようにalexa.appIdに変更するとWarningが消えます。

- alexa.APP_ID = APP_ID; // こちらは現在Warningとなる
+ alexa.appId = APP_ID; // 正しくはこちら

以上でClowdWatch上でWarningが消えるのを確認しました。

補足:アプリケーションIDを環境変数で指定する

ファイル内にスキルのアプリケーションIDを直書きするのもあれなのでAWS Lambdaにて環境変数を指定して記述するほうが良いかなと思います。

スキルのアプリケーションIDは開発者コンソールのAlexaスキルを管理するページで確認できます。

スクリーンショット 2018-01-31 20.46.28.png

AWS Lambdaの環境変数部分に以下のように記述しました。
環境変数名をALEXA_APP_ID、値に先程のアプリケーションIDを指定します。

スクリーンショット 2018-01-31 21.08.24.png

(TZはタイムゾーンの設定です)

Alexa Skillのindex.jsのAPP_ID部分に環境変数で指定します。

index.js
const APP_ID = process.env.ALEXA_APP_ID;

これでアプリケーションIDを直書きしなくて済みました。

3
5
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
3
5