GithubHelp home page GithubHelp logo

adamgilman / stairstep Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 6.0 475 KB

A Pythonic API for Amazon's States Language for defining AWS Step Functions

License: MIT License

Python 100.00%
python aws aws-step-functions state-machine state-lanague

stairstep's Introduction

stairstep

StairStep is a Pythonic API for designing AWS Step Functions using Amazon's State Language

Instead of hand crafting JSON, StairStep allows you define step functions using Python code which allows you to easily import information from outside sources and dynamically create step functions on the fly.

Development Progress / Coverage

Lanuage Feature Type Progress
State Pass
State Task
State Succeed
State Fail
State Choice
Field Common Validations
State Wait
State Parallel Next 🛣

Examples

Hello World

Using the example from the Amazon's State Language page

{
    "Comment": "A simple minimal example of the States language",
    "StartAt": "Hello World",
    "States": {
    "Hello World": { 
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
      "End": true
    }
  }
}

We can easily craft that in StairStep as follows

# Create a parent StairStep object
ss = StairStep(comment="A simple minimal example of the States language", startAt="Hello World")

# Create the HelloWorld step
hello = StateTask(name="Hello World", resource="arn:aws:lambda:us-east-1:123456789012:function:HelloWorld", end=True)

# Add the step into the StairStep object
ss.addState(hello)

# Create the Amazon State Language Export
ss.json()

{  
   "Comment":"A simple minimal example of the States language",
   "StartAt":"Hello World",
   "States":{  
      "Hello World":{  
         "Type":"Task",
         "Resource":"arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
         "End":true
      }
   }
}

hello_world

Complex Choice State

ss = StairStep(
    comment = "Example Choice State",
    startAt = "ChoiceStateX"
)
# Create a ChoiceRule, which is composed of choice expression(s)
# This checks to see if the variable $.type is not "Private"
typeNotPrivate = ChoiceRule(operator="Not", snext="Public", conditions=
    ChoiceExpression(operator="StringEquals", variable="$.type", value="Private")
)

# This checks to see if the value of $.value is >=20 or <30
valueInTwenties = ChoiceRule(operator="And", snext="ValueInTwenties", conditions=
    [
        ChoiceExpression(operator="NumericGreaterThanEquals", variable="$.value", value=20),
        ChoiceExpression(operator="NumericLessThan", variable="$.value", value=30)
    ]
)
state = StateChoice(name="ChoiceStateX", choices=[typeNotPrivate,valueInTwenties],default="DefaultState")

default = StatePass(name="DefaultState", end=True)
in_twenties = StatePass(name="ValueInTwenties", end=True)
public = StatePass(name="Public", end=True)

ss.addState(state)
ss.addState(in_twenties)
ss.addState(public)
ss.addState(default)
ss.json()
{
	"Comment": "Example Choice State",
	"StartAt": "ChoiceStateX",
	"States": {
		"ChoiceStateX": {
			"Type": "Choice",
			"Default": "DefaultState",
			"Choices": [{
				"Next": "Public",
				"Not": {
					"Variable": "$.type",
					"StringEquals": "Private"
				}
			}, {
				"Next": "ValueInTwenties",
				"And": [{
					"Variable": "$.value",
					"NumericGreaterThanEquals": 20
				}, {
					"Variable": "$.value",
					"NumericLessThan": 30
				}]
			}]
		},
		"ValueInTwenties": {
			"Type": "Pass",
			"End": true
		},
		"Public": {
			"Type": "Pass",
			"End": true
		},
		"DefaultState": {
			"Type": "Pass",
			"End": true
		}
	}
}

choice_state

stairstep's People

Contributors

adamgilman avatar sergiolucero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stairstep's Issues

StatePass has no validations

from stairstep import StateChoice, ChoiceRule, ChoiceExpression, StatePass

# Create a ChoiceRule, which is composed of choice expression(s)
# This checks to see if the variable $.type is not "Private"
typeNotPrivate = ChoiceRule(operator="Not", snext="Public", conditions=
    ChoiceExpression(operator="StringEquals", variable="$.type", value="Private")
)

# This checks to see if the value of $.value is >=20 or <30
valueInTwenties = ChoiceRule(operator="And", snext="ValueInTwenties", conditions=
    [
        ChoiceExpression(operator="NumericGreaterThanEquals", variable="$.value", value=20),
        ChoiceExpression(operator="NumericLessThan", variable="$.value", value=30)
    ]
)
state = StateChoice(name="ChoiceStateX", choices=[typeNotPrivate,valueInTwenties],default="DefaultState")

default = StatePass(name="DefaultState", end=True)
in_twenties = StatePass(name="ValueInTwenties", end=True)
public = StatePass(name="Public", end=True)

ss.addState(state)
ss.addState(in_twenties)
ss.addState(public)
ss.json()


>>> ss.json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dev2/Desktop/WORKING/stairstep/stairstep/base.py", line 100, in json
    return json.dumps( self.export() )
  File "/Users/dev2/Desktop/WORKING/stairstep/stairstep/base.py", line 85, in export
    states[k] = self.states[k].export()
  File "/Users/dev2/Desktop/WORKING/stairstep/stairstep/base.py", line 14, in export
    self.validate()
  File "/Users/dev2/Desktop/WORKING/stairstep/stairstep/base.py", line 9, in validate
    all_validations = self.base_validations + self.validations
AttributeError: 'StatePass' object has no attribute 'validations'

New PIP release ?

I need Parameters option and SAM CLI build command doesn't work very well with git dependencies. @adamgilman Could you please make a new release?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.