aws-cdk: (stepfunctions-tasks): LambdaInvoke - explicit null is not passed to lambda when using

When I try to pass null as some parameter of a lambda, it gets removed from resulting task’s parameters.

It might have same result for javascript lambdas, but in Python there is a difference between key not being in input event and key being there with value null (or None in Python’s case).

This issue can be worked around by adding additional checks in the lambda, but that would add additional step needed for migration to CDK.

Reproduction Steps

from aws_cdk import aws_lambda
from aws_cdk import aws_stepfunctions
from aws_cdk import aws_stepfunctions_tasks


some_lambda = aws_lambda.Function.from_function_arn(scope, 'SomeLambda', 'arn:aws:lambda:eu-central-1:123456789:function:some-lambda')

aws_stepfunctions_tasks.LambdaInvoke(
    scope,
    'Lambda',
    lambda_function=some_lambda,
    payload=aws_stepfunctions.TaskInput.from_object({
        'nullParameter': None,
        'notNullParameter': 'not null'
    }),
    payload_response_only=True,
    retry_on_service_exceptions=False
)

What did you expect to happen?

{
    "Type": "Task",
    "Resource": "arn:aws:lambda:eu-central-1:123456789:function:some-lambda",
    "Parameters": {
        "nullParameter": null,
        "notNullParameter": "not null"
    }
}

What actually happened?

{
    "Type": "Task",
    "Resource": "arn:aws:lambda:eu-central-1:123456789:function:some-lambda",
    "Parameters": {
        "notNullParameter": "not null"
    }
}

Environment

  • CDK CLI Version :1.118.0
  • Framework Version:???
  • Node.js Version:v15.14.0
  • OS :Ubuntu 18.04.5 LTS
  • Language (Version):Python 3.7.4

Other


This is 🐛 Bug Report

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Interesting workaround. Not something I would expect sfn.JsonPath.DISCARD to do, but it works

I faced a similar error when creating a pass state with null values. A quick solution is using sfn.JsonPath.stringToJson("") instead of null

        const passStateStoreItemLastEvaluatedKey = new sfn.Pass(this, `${resourcePrefix}-pass-store-item`, {
            parameters: {
                "Count.$": "$.Count",
                "EmailResult.$": "$.EmailResult",
                "projectId.$": "$.projectId",
                "ItemResult": {
                    "LastEvaluatedKey": sfn.JsonPath.stringToJson("")
                },
                "walletAddress.$": "$.walletAddress",
                "networkType.$": "$.networkType"
            },
            comment: "Transform store email result"
        });

@kaizen3031593 - I am actively working on a fix for this. Can you assign this issue to me?