Lambda×Slack連携テスト (Slack-echo-command-python)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
** 前提条件 [#oaa7c38c]
- AWSアカウント保有
- AWS CLIインストール済み(OS X 10.11 El Capitan)
- Slackアカウント保有
** SlackのWebhook設定確認 [#wd191ba3]
+ https://[slack名].slack.com/services/new にアクセス
+ 検索窓より[Slash Commands]を検索
+ "Slash Commands"をインストール
+ "Choose a Command"にコマンド名を入力(今回は[/sayhello]...
+ 設定画面遷移後に"Outgoing Data"の"token=<token name>"の...
** Tokenの暗号化 [#if4f86f0]
- 暗号化用のIAMユーザー作成
+ IAMユーザー名:lambdaSlackTest
+ IAMポリシー: ※今回はKMSによる暗号化のみ許可
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:Encrypt"
],
"Resource": "*"
}
]
}
- アクセスキーID、シークレットアクセスキー発行
- 暗号化キーの作成
+ AWSマネジメントコンソール >> IAM >> 暗号化キー よりキー...
~リージョン: アジアパシフィック(東京)~
エイリアス:lambdaSlackTest
+ "キー管理者"に作成したIAMユーザー"lambdaSlackTest"を追加
- AWS CLIの認証情報設定
$ aws configure
AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json
- Slack認証用のToken暗号化
$ aws kms encrypt --key-id alias/lambdaSlackTest --plain...
{
"KeyId": "arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:ke...
"CiphertextBlob": "<encrypted token>"
}
** Lambda Function作成 [#p90faecf]
- "Select blueprint"より"slack-echo-command-python"を選択
~Name: Slack-echo-command-python~
Runtime: Python 2.7~
Role: lambda-slack-integration-test ※新規作成
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx...
]
}
]
}
- "Advanced settings"は初期値
- "Next"をクリック
- "Create function"をクリック
** IAM Roleの追加 [#i0b45363]
- Cloudwatch LogsへのアクセスとPUT権限を付与したIAM Role...
~ポリシー名:putlogs~
ポリシー:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
- Lambda functionのCode編集画面より"ENCRYPTED_EXPECTED_TO...
- "Test"をクリックし下記のコードを入力(<token name>はSla...
{
"body":
"token=<token name>&team_id=T0001&team_domain=example&ch...
}
- "Execution result"が"succeeded"となり下記が出力されればOK
"Steve invoked /weather in test with the following text:...
** API Endpoint追加 [#lb037923]
+ Lambda Functions >> "slack-echo-command-python" >> "API...
~API endpoint type: API Gateway~
API name: LambdaPythonSlackintegrationTest~
Resource name: /Slack-echo-command-python~
Method: POST~
Deployment stage: prod~
Security: Open
+ "Submit"をクリック
** API Gateway設定 [#i3b55738]
+ /Slack-echo-command-python >> "統合リクエスト"をクリック
+ "マッピングテンプレートの追加"をクリック
~Content-Type: application/x-www-form-urlencoded~
Template: { "body": $input.json("$") }
+ "保存"をクリック
+ "アクション" >> "APIのデプロイ" >> デプロイされるステー...
** SlackのWebhook設定 [#ab1fd176]
- Integration Settings >> URL にAPI Endpointを入力
https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws....
- Method: POST
- Slackアプリより"slackbot"に下記入力
/sayhello test
- slackbotが下記を返したら成功
"<user> invoked /sayhello in directmessage with the foll...
終了行:
** 前提条件 [#oaa7c38c]
- AWSアカウント保有
- AWS CLIインストール済み(OS X 10.11 El Capitan)
- Slackアカウント保有
** SlackのWebhook設定確認 [#wd191ba3]
+ https://[slack名].slack.com/services/new にアクセス
+ 検索窓より[Slash Commands]を検索
+ "Slash Commands"をインストール
+ "Choose a Command"にコマンド名を入力(今回は[/sayhello]...
+ 設定画面遷移後に"Outgoing Data"の"token=<token name>"の...
** Tokenの暗号化 [#if4f86f0]
- 暗号化用のIAMユーザー作成
+ IAMユーザー名:lambdaSlackTest
+ IAMポリシー: ※今回はKMSによる暗号化のみ許可
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:Encrypt"
],
"Resource": "*"
}
]
}
- アクセスキーID、シークレットアクセスキー発行
- 暗号化キーの作成
+ AWSマネジメントコンソール >> IAM >> 暗号化キー よりキー...
~リージョン: アジアパシフィック(東京)~
エイリアス:lambdaSlackTest
+ "キー管理者"に作成したIAMユーザー"lambdaSlackTest"を追加
- AWS CLIの認証情報設定
$ aws configure
AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json
- Slack認証用のToken暗号化
$ aws kms encrypt --key-id alias/lambdaSlackTest --plain...
{
"KeyId": "arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx:ke...
"CiphertextBlob": "<encrypted token>"
}
** Lambda Function作成 [#p90faecf]
- "Select blueprint"より"slack-echo-command-python"を選択
~Name: Slack-echo-command-python~
Runtime: Python 2.7~
Role: lambda-slack-integration-test ※新規作成
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:ap-northeast-1:xxxxxxxxxxxx...
]
}
]
}
- "Advanced settings"は初期値
- "Next"をクリック
- "Create function"をクリック
** IAM Roleの追加 [#i0b45363]
- Cloudwatch LogsへのアクセスとPUT権限を付与したIAM Role...
~ポリシー名:putlogs~
ポリシー:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
- Lambda functionのCode編集画面より"ENCRYPTED_EXPECTED_TO...
- "Test"をクリックし下記のコードを入力(<token name>はSla...
{
"body":
"token=<token name>&team_id=T0001&team_domain=example&ch...
}
- "Execution result"が"succeeded"となり下記が出力されればOK
"Steve invoked /weather in test with the following text:...
** API Endpoint追加 [#lb037923]
+ Lambda Functions >> "slack-echo-command-python" >> "API...
~API endpoint type: API Gateway~
API name: LambdaPythonSlackintegrationTest~
Resource name: /Slack-echo-command-python~
Method: POST~
Deployment stage: prod~
Security: Open
+ "Submit"をクリック
** API Gateway設定 [#i3b55738]
+ /Slack-echo-command-python >> "統合リクエスト"をクリック
+ "マッピングテンプレートの追加"をクリック
~Content-Type: application/x-www-form-urlencoded~
Template: { "body": $input.json("$") }
+ "保存"をクリック
+ "アクション" >> "APIのデプロイ" >> デプロイされるステー...
** SlackのWebhook設定 [#ab1fd176]
- Integration Settings >> URL にAPI Endpointを入力
https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws....
- Method: POST
- Slackアプリより"slackbot"に下記入力
/sayhello test
- slackbotが下記を返したら成功
"<user> invoked /sayhello in directmessage with the foll...
ページ名: