5
1

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.

CloudWatch Event Rule Targets Configure input の種類

Posted at
20180521_cw_event_input_01.png

Matched event (一致したイベント)

イベント全体をそのまま渡す。

Part of the matched event (一致したイベントの一部)

  • CloudFormation property: InputPath

イベントの一部をJSONPath形式で指定して渡す。複数指定不可。

$.detail

Constant (JSON text) (定数 JSONテキスト)

  • CloudFormation property: Input

任意のJSON文字列をJSON形式で渡す。

{ "key": "value", "hoge": [ 1, true, "fuga" ] }

Input Transformer (インプットトランスフォーマー)

  • CloudFormation property: InputTransformer
    • InputPathsMap
    • InputTemplate

テンプレートに基づいた 文字列 を渡す

Input Path

Key-Value形式でJSONPath(ドット表記)を記述。

{ "state": "$.detail.state", "instance": "$.detail.instance-id" }

Input Template

渡される文字列のテンプレート。Input Path 定義(プレースホルダ)は "<>" で囲む。

"The state of Instance <instance> is <state>"

Lambda 内でJSON形式で利用する

Input Template に JSON文字列 を定義し、
JSON文字列 として渡し、Lambda側で変換する。

  • ダブルクォーテーションで囲む
  • 内部のダブルクォーテーションをエスケープ
  • 改行不可
"{ \"DetailType\": \"<DetailType>\", \"Source\": \"<Source>\" }"

Python

  • Input Transformer 以外は dict で渡る
import json
def lambda_handler(event, context):
    if type(event) == str:
        event = json.loads(event)

Node.js

  • Input Transformer 以外は object で渡る
exports.handler = async (event) => {
    if (typeof(event) == "string") {
        event = JSON.parse(event);
    }
};
5
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?