Package: sfini
sfiniCreate, run and manage AWS Step Functions easily. Pronounced "SFIN-ee".This package aims to provide a user-friendly interface into defining and
running Step Functions. Things you can do insfinito interact with AWS Step
Functions:Implement and register activitiesDefine and register state machinesStart, track and stop executionsRun workers for activitiesGet information for registered activities and state machinesDe-register state machines and activitiesNote: this is not a tool to convert Python code into a Step Functions state
machine. For that, seepyawssfn.Getting startedPrerequisitesAWS(Amazon Web Services) account, with
access to Step FunctionsAWSIAM(Identity and Access Management)
credentialsInstallationpipinstallsfiniUsageDocumentationCheck thedocumentationor use
the built-in help:pydocsfiniimportsfinihelp(sfini)AWS Step FunctionsAWS Step Functions(SFN) is a
workflow-management service, providing the ability to coordinate tasks in a
straight-forward fashion. Further documentation can be found in theAWS documentation.Usage of Step Functions consists of two types: state-machines and activities.
A state-machine is a graph of operations which defines a workflow of an
application, comprised of multiple types of "states", or stages of the
workflow. An activity processes input to an output, and is used to process a
task "state" in the state-machine (multiple task states can have the same
activity assigned it.Once a state-machine is defined and registered (along with the used
activities), you run executions of that state-machine on different inputs to
run the workflow.sfiniallows you to start, stop and get the history of
these executions.State-machines support conditional branching (and therefore loops), retries
(conditional and unconditional), exception-catching, external AWS service
support for running tasks, parallel execution and input/output processing.
External services including AWS Lambda, so you don't have to deploy your own
activity runners.Once state-machines and activities are defined and registered, you can view and
update their details inthe SFN web console.Role ARNEvery state-machine needs a role ARN (Amazon Resource Name). This is an AWS IAM
role ARN which allows the state-machine to process state executions. See AWS
Step Functions documentation for more information.ExampleMore examples foundin the documentation.importsfini# Define activitiesactivities=sfini.ActivityRegistration(prefix="test")@activities.activity("addActivity")defadd_activity(data):returndata["a"]+data["b"]# Define state-machineadd=sfini.Task("add",add_activity)sm=sfini.construct_state_machine("testAdding",add)# Register state-machine and activitiesactivities.register()sm.register()# Start activity workerworker=sfini.Worker(add_activity)worker.start()# Start executionexecution=sm.start_execution(execution_input={"a":3,"b":42})print(execution.name)# testAdding_2019-05-13T19-07_0354d790# Wait for execution and print outputexecution.wait()print(execution.output)# 45print(execution.format_history())# ExecutionStarted [1] @ 2019-06-23 20:03:52.817000+10:00# TaskStateEntered [2] @ 2019-06-23 20:03:52.840000+10:00:#   name: add# ActivityScheduled [3] @ 2019-06-23 20:03:52.840000+10:00:#   resource: arn:aws:states:us-west-2:ACCID:activity:testaddActivity# ActivityStarted [4] @ 2019-06-23 20:03:53.954000+10:00:#   worker: hostname-3a4fb480# ActivitySucceeded [5] @ 2019-06-23 20:03:55.028000+10:00# TaskStateExited [6] @ 2019-06-23 20:03:55.028000+10:00:#   name: add# ExecutionSucceeded [7] @ 2019-06-23 20:03:55.028000+10:00# Output: 45# Stop activity workersworker.end()worker.join()# Deregister state-machine and activitiesactivities.deregister()sm.deregister()