1

I have tried to look throught the internet, but none of the solutions seem to work for me in python. Basicly I want to transfer some parameters from one lambda function to the next lambda function in a step function. I was a bit surprised how hard it is to find a simple example of how to do this?

So my first lambda function has an output like:

return {"user_name" : user_name, "region" : region, "instance_id" : instance_id}

And my second lambda function tries to import with:

user_name = event["user_name"]
region = event["region"]
instance_id = event["instance_id"]

My stepfunction looks like:

{
         "StartAt": "CreateEC2Instance",
         "States": {
           "CreateEC2Instance": {
             "Type": "Task",
             "Resource": "arn:aws:states:::lambda:invoke",
             "Parameters": {
               "FunctionName": "MY_ARN_1",
               "Payload": {
                  "region": "eu-central-1",
                  "user_name": "MY_USERNAME"
              }},
             "Next": "AttachEFStoEC2"
           },
            "AttachEFStoEC2": {
             "Type": "Task",
             "Resource":"MY_ARN_2",
             "End": true
         }

the error is:

{
  "error": "KeyError",
  "cause": {
    "errorMessage": "'user_name'",
    "errorType": "KeyError",
    "stackTrace": [
      "  File \"/var/task/lambda_function.py\", line 7, in lambda_handler\n    user_name = event[\"user_name\"]\n"
    ]
  }
}

1 Answer 1

4
{
         "StartAt": "CreateEC2Instance",
         "States": {
           "CreateEC2Instance": {
             "Type": "Task",
             "Resource": "arn:aws:states:::lambda:invoke",
             "ResultPath": "$.randomstring",
             "Parameters": {
               "FunctionName": "MY_ARN_1",
               "Payload": {
                  "region": "eu-central-1",
                  "user_name": "MY_USERNAME"
              }},
             "Next": "AttachEFStoEC2"
           },
            "AttachEFStoEC2": {
             "Type": "Task",
             "Resource":"MY_ARN_2",
                   "Parameters": {
                       "outputfromearlierfunction.$": "$.randomstring.Payload"
                   },
             "End": true
         }

and then try to access within the function like

receivedinput = event.get('outputfromearlierfunction')
user_name = receivedinput["user_name"]
region = receivedinput["region"]
instance_id = receivedinput["instance_id"]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Your explanation really helped me understand how parameters are stored :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.