Skip to main content

AWS Step Functions: state machine boilerplate generator

Project description

AWS Step Functions State Machine builder.

The primary motivation for this was the amount of boilerplate (Next, End) required to compose a valid state machine definition, but soon one got carried away.

Python 3.6+ only.

Installation

pip install aws-sfn-builder

Generate State Machine Definition from Simple Description

from aws_sfn_builder import Machine

Machine.parse([
    "a",
    [
        ["b-10", "b-11"],
        ["b-20"],
    ],
    "c",
]).to_json()

This will generate:

{
    "StartAt": "a",
    "States": {
        "a": {
            "Type": "Task",
            "Next": "d3d52323-137d-4228-9956-d3b77cc43a92"
        },
        "d3d52323-137d-4228-9956-d3b77cc43a92": {
            "Type": "Parallel",
            "Next": "c",
            "Branches": [
                {
                    "StartAt": "b-10",
                    "States": {
                        "b-10": {
                            "Type": "Task",
                            "Next": "b-11"
                        },
                        "b-11": {
                            "Type": "Task",
                            "End": true
                        }
                    }
                },
                {
                    "StartAt": "b-20",
                    "States": {
                        "b-20": {
                            "Type": "Task",
                            "End": true
                        }
                    }
                }
            ]
        },
        "c": {
            "Type": "Task",
            "End": true
        }
    }
}

Parse Existing State Machine Definition

# TODO load state_machine_json_dict

state_machine = Machine.parse(state_machine_json_dict)

Compile State Machine

# TODO initialise state_machine

state_machine.compile()

Test Your State Machine

Work in progress.

# TODO initialise state_machine

runner = Runner()

@runner.resource_provider("arn:aws:lambda:us-east-1:123456789012:function:Foo")
def foo(input):
    return "foo-result"

final_state, output = runner.run(state_machine)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aws-sfn-builder, version 0.0.10
Filename, size File type Python version Upload date Hashes
Filename, size aws_sfn_builder-0.0.10-py3-none-any.whl (11.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size aws-sfn-builder-0.0.10.tar.gz (11.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page