Search code examples
powershellaws-lambdaaws-step-functions

How to pass parameter from AWS Step Functions to PowerShell AWS Lambda?


Into simple AWS Lambda PowerShell script I'm passing parameter called tokens in JSON form:

{ "tokens": "ABC123" }

This is being read by Script as variable $LambdaInput.tokens which is expected by Lambda script by design.

Inside Step Function template I have specified Parameter tokens:

  {
    "Comment": "Start Script",
    "StartAt": "PowerShellScript1",
    "States": {
      "PowerShellScript1": {
        "Type": "Task",
        "Resource": "arn:aws:states:::lambda:invoke",
        "Parameters": {
          "FunctionName": "arn:aws:lambda:XYZ:function:PowerShellScript1:$LATEST",
          "Payload": {
            "Input": {
              "tokens": "ABC123"
            }
          }
        },
        "End": true,
        "TimeoutSeconds": 60
      }
    }
  }

Unfortunately my Lambda script can't recongnize the parameter. I expect it's not being inserted as variable $LambdaInput.tokens.

Is there different Input variable for PowerShell script from Step Functions than from simple Lambda?

Thank you.


Solution

  • Thanks to Joe's comment leading to his answer here I managed to form the appropriate definition of State Machines to pass the Parameter to PowerShell Lambda script:

    {
      "Comment": "Start Script",
      "StartAt": "PowerShellScript1",
      "States": {
        "PowerShellScript1": {
          "Type": "Task",
          "Resource": "arn:aws:lambda:XYZ:function:PowerShellScript1:$LATEST",
          "Parameters": {
            "tokens": "ABC123"
          },
          "End": true
        }
      }
    }