AWS CDK AWS Step Functions

1.204.0 · active · verified Fri Apr 17

The `aws-cdk-aws-stepfunctions` library is the AWS Cloud Development Kit (CDK) Construct Library for defining AWS Step Functions state machines in Python. It allows developers to programmatically create and manage Step Functions workflows, including states, tasks, and error handling. As of version `1.204.0`, this package is part of the AWS CDK v1 ecosystem, which typically sees frequent updates aligning with broader CDK releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic AWS Step Functions State Machine using a simple 'Pass' state. It initializes a CDK application, creates a stack, defines the Pass state with a basic JSON definition, and then constructs a `StateMachine` resource. The `app.synth()` call generates the AWS CloudFormation template. To deploy, ensure AWS credentials are configured and run `cdk deploy MyStepFunctionStack` in your terminal.

import os
from aws_cdk import core as cdk
from aws_cdk import aws_stepfunctions as sfn

# Define your CDK Stack
class MyStepFunctionStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Define a simple Pass state
        pass_state = sfn.Pass(self, "MyPassState",
            state_json={
                "Comment": "A simple pass state for demonstration",
                "InputPath": "$",
                "OutputPath": "$",
                "Result": {"status": "SUCCESS", "source": "CDK"},
                "End": True
            }
        )

        # Define a State Machine using the Pass state
        sfn.StateMachine(self, "MyCDKStateMachine",
            definition=pass_state,
            state_machine_name="MyCDKPassStateMachine", # Optional: explicit name
            timeout=cdk.Duration.minutes(5) # Optional: default timeout
        )

# Instantiate the CDK App and Stack
app = cdk.App()
MyStepFunctionStack(app, "MyStepFunctionStack")
app.synth()

view raw JSON →