The next step is... AWS Step Functions

June 28, 2022

Last time I participated in workshops about AWS Step Functions. This service provided by AWS was created for implementing flow of our application and close the paths in state machine. This service can be created and maintained from Serverless Framework which is one of the most popular frameworks to manage cloud resources and applications. The mentors created a repository to start our journey and resolve tasks during 2 days workshop.

Advantages of step functions:

  • allow us to manage many of services in our cloud applications (ex. lambdas)
  • visualize steps and executed path
  • easily to find logs, passed inputs/outputs
  • ASL to declare step flow
  • usage with frameworks as Serverless Framework
  • developing locally (Serverless framework with plugin)
  • move our thinking to implement our application as small possible steps
  • possible to usage other aws services from steps declaration

Started repository:
My repository:
Step functions and Severless framework:

I will go through some examples/features

ASL - Amazon State Language

Most of examples in the documentation are in JSON bu using SF we can describe it in yml

Step types

The powerful of ASF we can see on more complicated flow. Below You can see the Choice type. Similary to switch() or match() functions in programming languages. This is our first step of flow. As we can se there are some other keywords as StringEquals to compare returned parameter.

Comment: "Scan user CV document for data"
StartAt: checkFileType
    Type: Choice
      - Variable: $.extension
        StringEquals: "txt"
        Comment: Is a text file?
        Next: copyFileToExtractedBucket
    Default: extractData

Choice type allows to use other keywords to compare input.

For example NumericGreaterThan for numeric comparison

    Type: Choice
      - Variable: $.calculatedScore
        NumericGreaterThan: 100
        Comment: Is a match?
        Next: saveToMatchedBucket
    Default: saveToRejectedBucket

Calling services

The next one will be step with calling other service like textract:analyzeDocument.

Full list of integrations:

AWS service we define like arn:aws:states:::aws-sdk:[service]:[apiAction]

    Type: Task
    Resource: arn:aws:states:::aws-sdk:textract:analyzeDocument
          Bucket: !Ref inputBucket
          Name.$: $.key
        - TABLES
        - FORMS
    ResultPath: "$.taskresult"
    Next: extractTe

Parallel step execution

The best thing is that we haven’t wait for all services using language mechanism of asynchronous execution. I this case the result of all parallel steps will be passed to calculateScore at once, like one event in lambda handler.

    Type: Parallel
      - StartAt: checkNodeExperience
            Type: Task
            Resource: !GetAtt checkNodeExperience-lambda.Arn
            End: true
      - StartAt: checkCloudExperience
            Type: Task
            Resource: !GetAtt checkCloudExperience-lambda.Arn
            End: true
      - StartAt: checkItExperience
            Type: Task
            Resource: !GetAtt checkItExperience-lambda.Arn
            End: true
      - StartAt: checkExcludeLists
            Type: Task
            Resource: !GetAtt checkExcludeLists-lambda.Arn
            End: true
    Next: calculateScore

Full workflow implemented on workshop


Of course, the step functions has a lot of more features like graphical editor, executing in loops and others.

Best, Marcin

Profile picture

Written by Marcin Gładkowski

This is the place where you can find some my toughts, ideas, summaries etc.

© 2022, Marcin Gładkowski