简体   繁体   English

SSM 自动化文档无法在 Lambda 调用结果上使用输出或 JSONPath

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

I am not able to use JSONPath syntax on the response from lambda in SSM Document nor able to use the outputs defined in one step as input to next one.我无法对来自 SSM 文档中 lambda 的响应使用 JSONPath 语法,也无法将一步中定义的输出用作下一步的输入。

Questions:问题:

  1. How to extract the 'resultParam1' from 'MyLambda1's response and use it as input for MyStep2?如何从“MyLambda1”的响应中提取“resultParam1”并将其用作 MyStep2 的输入?
  2. Why 'ResParam' is not working?为什么“ResParam”不起作用?

Not sure I am missing some basic item, please help.不确定我缺少一些基本项目,请帮忙。

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

Lambda1:拉姆达1:

import json

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

Just after posting this question, found the answer.刚刚发布了这个问题,就找到了答案。

Though we see output in SSM execution for MyStep1 as string for payload虽然我们在 MyStep1 的 SSM 执行中看到 output 作为有效负载的字符串

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

The selector should not be specified as '$.Payload.resultParam1'.不应将选择器指定为“$.Payload.resultParam1”。 We could directly use '$.resultParam1'.我们可以直接使用'$.resultParam1'。 The placeholder tooltip on the Builder UI in console while specifying this somehow mislead me.控制台中 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