Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AWS states Language interpreter #37

Open
s8sg opened this issue Feb 20, 2019 · 2 comments
Open

Make AWS states Language interpreter #37

s8sg opened this issue Feb 20, 2019 · 2 comments

Comments

@s8sg
Copy link
Owner

s8sg commented Feb 20, 2019

The main idea here is to make use of AWS State Language to define pipelines

@vtolstov
Copy link
Contributor

i can take this if you provide info for first steps. As i understand i need to parse aws step defintions in json and create Workflow with needed Dags.

@s8sg
Copy link
Owner Author

s8sg commented Jul 26, 2019

Great. We might not support all the features of step functions, but for now we can create a dag definition based on what we support. One amazon state language specification example I was looking at

{
  "Comment": "An example of the Amazon States Language using a choice state.",
  "StartAt": "FirstState",
  "States": {
    "FirstState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:FUNCTION_NAME",
      "Next": "ChoiceState"
    },
    "ChoiceState": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.foo",
          "NumericEquals": 1,
          "Next": "FirstMatchState"
        },
        {
          "Variable": "$.foo",
          "NumericEquals": 2,
          "Next": "SecondMatchState"
        }
      ],
      "Default": "DefaultState"
    },

    "FirstMatchState": {
      "Type" : "Task",
      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:OnFirstMatch",
      "Next": "NextState"
    },

    "SecondMatchState": {
      "Type" : "Task",
      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:OnSecondMatch",
      "Next": "NextState"
    },

    "DefaultState": {
      "Type": "Fail",
      "Error": "DefaultStateError",
      "Cause": "No Matches!"
    },

    "NextState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:FUNCTION_NAME",
      "End": true
    }
  }
}

The corresponding generated dag contructs in faas-flow will be like

       dag := flow.Dag()
       dag.Node("FirstState").Apply("FUNCTION_NAME")
       conditionalDags := dag.ConditionalBranch("ChoiceState",
                []string{"1", "2", "default"}, // possible conditions
                func(response []byte) []string {
                        result := &struct{
                                  Foo int      `json:"foo"`
                        }{} 
                        json.Load(response, &result)
                        switch result.Foo {
                              case 1:
                                      return []string{fmt.Sprintf("%s", result. Foo)}
                              case 2:
                                      return []string{fmt.Sprintf("%s", result. Foo)}
                        } 
                        return []string{ "default" }
                },
       )
       conditionalDags["1"].Node("FirstMatchState").Apply("OnFirstMatch")
       conditionalDags["2"].Node("SecondMatchState").Apply("OnSecondMatch")
       conditionalDags["default"].Node("DefaultState").Modify(func(data []byte) ([]byte, error) {
                return data, faasflow.AWSDefaultStateError
       })
       dag.Node("NextState").Apply("FUNCTION_NAME")
       dag.Edge("FirstState", "ChoiceState")
       dag.Edge("ChoiceState", "NextState")

The goal is to provide an sdk function like

dag  = flow.GenerateDag(faasflow.AwsStateLang, defnition)
flow.SetDag(dag)

I can't quite get my head around that how will we create the flow defnition from the parse data, it seems there will be a lot of callbacks and datastructure involved. I guess best to start with simple example, like only dag no conditions. Its great if you can give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants