简体   繁体   中英

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.

Questions:

  1. How to extract the 'resultParam1' from 'MyLambda1's response and use it as input for MyStep2?
  2. Why 'ResParam' is not working?

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:

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

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

The selector should not be specified as '$.Payload.resultParam1'. We could directly use '$.resultParam1'. The placeholder tooltip on the Builder UI in console while specifying this somehow mislead me.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM