簡體   English   中英

SSM 自動化文檔無法在 Lambda 調用結果上使用輸出或 JSONPath

[英]SSM Automation Document Unable to use Outputs or JSONPath on Lambda invoke results

我無法對來自 SSM 文檔中 lambda 的響應使用 JSONPath 語法,也無法將一步中定義的輸出用作下一步的輸入。

問題:

  1. 如何從“MyLambda1”的響應中提取“resultParam1”並將其用作 MyStep2 的輸入?
  2. 為什么“ResParam”不起作用?

不確定我缺少一些基本項目,請幫忙。

description: Sample document
schemaVersion: '0.3'
parameters:
  param1:
    type: String
    default: 'true'
  param2:
    type: String
    default: ''
  param3:
    type: String
    default: 'false'
mainSteps:
  - name: MyStep1
    action: 'aws:invokeLambdaFunction'
    inputs:
      InvocationType: RequestResponse
      FunctionName: MyLamda1
      InputPayload:
        param1: '{{param1}}'
        param2: '{{param2}}'
        param3: '{{param3}}'
    description: Initiate phase 1
    outputs:
      - Name: ResParam
        Selector: $.Payload
        Type: StringMap
  - name: MyStep2
    action: 'aws:invokeLambdaFunction'
    inputs:
      InvocationType: RequestResponse
      FunctionName: MyLamda2
      InputPayload:
        /* 

        1. {{MyStep1.Payload.resultParam1}} -> Error received as noted below.This is probably because MyStep1.Payload is treated as string.

        :Failed to resolve input: MyStep1.Payload.resultParam1 to type Integer or Boolean or String or StringList or StringMap or MapList. MyStep1.Payload.resultParam1 is not defined in the Automation Document". 

        2. '{{MyStep1.ResParam}}' doesn't work either. Because the Payload appears to be a string even if lambda returns json. The MyLamda2 receives param2 as "{{MyStep1.ResParam}}" instead of actual value
            This is the Payload output seen in step 1 - {\"resultParam1\": \"Hello\", \"resultParam2\": \"World\"}
        */
        param2: '{{MyStep1.Payload.resultParam1}}'
    description: Initiate phase 2

拉姆達1:

import json

def lambda_handler(event, context):
    print(f"Event received {event}")
    result = {"resultParam1": "Hello", "resultParam2": "World"}
    return result

剛剛發布了這個問題,就找到了答案。

雖然我們在 MyStep1 的 SSM 執行中看到 output 作為有效負載的字符串

Payload: {\"resultParam1\": \"Hello\", \"resultParam2\": \"World\"}

不應將選擇器指定為“$.Payload.resultParam1”。 我們可以直接使用'$.resultParam1'。 控制台中 Builder UI 上的占位符工具提示,同時指定它以某種方式誤導了我。

    outputs:
      - Name: ResParam
        Selector: $.resultParam1
        Type: StringMap
  - name: MyStep2
    action: 'aws:invokeLambdaFunction'
    inputs:
      InvocationType: RequestResponse
      FunctionName: MyLamda2
      InputPayload:
          param2: '{{MyStep1.ResParam}}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM