跳转到主要内容

AWS Step Functions: 状态机样板生成器

项目描述

AWS Step Functions 状态机构建器。

这个项目的初衷是减少编写有效的状态机定义所需的样板代码(如Next,End),但很快就越做越多。

仅支持Python 3.6+

安装

pip install aws-sfn-builder

从简单描述生成状态机定义

from aws_sfn_builder import Machine

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

这将生成

{
    "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
        }
    }
}

解析现有状态机定义

# TODO load state_machine_json_dict

state_machine = Machine.parse(state_machine_json_dict)

编译状态机

# TODO initialise state_machine

state_machine.compile()

测试您的状态机

进行中。

# 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)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源分发

aws-sfn-builder-0.0.10.tar.gz (11.0 kB 查看哈希值)

上传时间

构建分发

aws_sfn_builder-0.0.10-py3-none-any.whl (11.9 kB 查看哈希)

上传于 Python 3

由以下支持