LoginSignup
4
2

More than 5 years have passed since last update.

LambdaにAlexa Smart HomeのトリガーをAWS CLI / Terraformから追加する

Last updated at Posted at 2018-06-01

結論から先に言うと

  • AWS CLIからadd-permissionを実行する。その際、以下の設定が必要
    • principalにalexa-connectedhome.amazon.comを指定
    • event-source-tokenにAlexa Smart HomeのスキルIDを指定
    • source-arnは特に指定しない
    • terraformからはevent-source-tokenを指定できないため、Alexa Smart Homeのトリガーは設定できない(2018/06/01現在)

前提

Alexa Smart Home SkillのコードはAWS上でLambda関数としてホストされる。

そのために、Alexaコンソールに表示されているスキルIDを指定して、Alexa Smart HomeをLambdaのトリガーとして設定しなければならない。

image.png

AWS Console上で設定する方法はドキュメントに記載されていたが、AWS CLIまたは、Terraformで設定したかった。

AWS CLIからAlexa Smart Homeのトリガー設定

以下の通り指定することで LambdaにAlexa Smart Homeのトリガーを追加することができる。

aws lambda add-permission \
--region us-west-2 \
--function-name (対象のLambda Function名) \
--statement-id (statement-id) \
--principal alexa-connectedhome.amazon.com \
--action lambda:InvokeFunction \
--event-source-token (Alexa Smart HomeのスキルID)

Lambdaからadd-permissionする際は、ARNを指定する場合が多いが、Alexa Smart Homeの場合はevent-source-tokenにスキルIDを指定する。

Principalはalexa-connectedhome.amazon.comを指定。

TerraformからAlexa Smart Homeのトリガー設定

当初、terraformで上記の設定を行えないかと調べたが、event_source_tokenが設定できないため、SmartHomeSkillのトリガー追加には未対応のようでissueが挙げられていた。(2018/06/01現在)

Terraformからも、event_source_tokenを指定することができるようになったため、
同様の設定内容を指定することで、トリガーを追加することができる。
https://www.terraform.io/docs/providers/aws/r/lambda_permission.html#event_source_token
https://github.com/terraform-providers/terraform-provider-aws/pull/5264

event-source-tokenの詳細は公式ドキュメントに記載されている

余談

ちなみに、カスタムスキルのトリガー設定方法については、公式ドキュメントに記載されている
https://developer.amazon.com/ja/docs/custom-skills/host-a-custom-skill-as-an-aws-lambda-function.html#use-aws-cli

4
2
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
4
2