aws step function set resource data using cdk

Viewed 139

Hi I am creating a step function using python cdk and my step function code look like this :

state_machine = sfn.StateMachine(
    self,
    "MyStateMachine",
    definition=tasks.LambdaInvoke(
        self,
        "MyLambdaTask",
        lambda_function=hello_function
    ).next(
        sfn.Succeed(
            self,
            "GreetedWorld"
        )
    )
)

and here just I want to add this configurations to wait for token using python cdk:

as I added this configuration on aws dashboard directly in edit state machine json

"Resource": "arn:aws:states:::lambda:invoke.waitForTaskToken",

want to add this line of code using python cdk . can't find way to add this

1 Answers

As I understand it, you want to invoke your Lambda function asynchronously and wait for the response token.

To do this in CDK, you can specify the integration type for the LambdaInvoke action, as well as pass the token to the handler:

state_machine = sfn.StateMachine(
    self,
    "MyStateMachine",
    definition=tasks.LambdaInvoke(
        self,
        "MyLambdaTask",
        lambda_function=hello_function,
        integration_pattern=tasks.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
        payload={"token.$":"$$.Task.Token"},
    ).next(
        sfn.Succeed(
            self,
            "GreetedWorld"
        )
    )
)

References:

https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions_tasks.LambdaInvoke.html#integrationpattern

Related