0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS IoT Events JSONカスタムペイロードのエラーの解決方法

Last updated at Posted at 2025-03-12

はじめに

AWS IoT Eventsで、イベント発行時のカスタムペイロードでエラーがなかなか解消できずにはまったので解決方法を紹介する。

動作確認環境

エラー内容

探知器モデルを保存して発行しようとすると、以下のようなエラーが発生する。

image.png

探知器モデルを更新できませんでした。DetectorModelDefinition is invalid due to: We couldn't parse your content expression for the payload of IotTopicPublishAction. Enter a content expression with the correct syntax. Error found in state Shutdown in onInput in event test in action IotTopicPublishAction.

解決方法

公式ドキュメントに以下のような記載がある。

The content of the payload. You can use a string expression that includes quoted strings ('<string>'), variables (\$variable.<variable-name>), input values (\$input.<input-name>.<path-to-datum>), string concatenations, and quoted strings that contain \${} as the content. The recommended maximum size of a content expression is 1 KB.
Type: String
Length Constraints: Minimum length of 1.
Required: Yes

まとめると、カスタムペイロードのcontentExpressionは、以下のように記述する必要がある。

  • カスタムペイロード全体をシングルクオーテーション(')で囲む
  • 文字列、変数、入力、文字列の連結を利用できる
  • 入力や変数を参照する場合は、${}で囲む
    • 入力($input.<input-name>.<path-to-datum>)を参照する場合
      • ${$input.<input-name>.<path-to-datum>}
        • <input-name> : 入力名
        • <path-to-datum> : 入力のJSONフィールド名
    • 変数($variable.<variable-name>)を参照する場合
      • ${$variable.<variable-name>}
        • <variable-name>: 変数名
  • 文字列型の入力や変数は、ダブルクォーテーション(")で囲み文字列とする
    • 入力($input.inputName.stringName)の場合
      • "${$input.inputName.stringName}"
        • inputName : 入力名
        • stringName : 文字列のフィールド名
  • ペイロードの推奨最大サイズ:1KB

GUIで設定する場合の例を示す。カスタムペイロードを選択すると以下のような設定画面となる。

image.png

  • ペイロードタイプ
    • 「JSON」を選択
  • カスタムペイロード
    • 上述のルールにあるようにペイロードを文字列で記載
カスタムペイロードの例
'
{
  "inputStringName": "${$input.<inputName>.stringName}",
  "variableStringName": "${$variable.<variableName>.stringName}",
  "inputNumberName": ${$input.<inputName>.numberName},
  "variableNumberName": ${$variable.<variableName>.numberName}
}
'
  • ポイント
    • 文字列型の入力や変数を扱う場合は、ダブルクォーテーション("")で囲む
カスタムペイロード結果の例
{
  "inputStringKeyName": "aaa",
  "variableStringKeyName": "bbb",
  "inputNumberKeyName": 0,
  "variableNumberKeyName": 1
}

まとめ

AWS IoT Eventsにおいて、イベント発行時のカスタムペイロードのエラー解決方法を紹介した。IoT Eventsのカスタムペイロードは記法が独特なので公式ドキュメントをよく読んで正しく設定することが重要。

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?