Step Functions

step

with

UP

Overview

  • Why would we use step functions?
  • How does that look in practice?
  • What mistakes I have made?
  • Are there rules you should follow?
  • What have I not tried yet?

About Me

  • Thomas Ankcorn
  • Senior Software Engineer at Baselime
  • Working with serverless and AWS for 4 years
  • @thomasankcorn on twitter
  • Forged at BAE Systems

who has used step functions?

why step functions?

Supportability Maintainability
Extendability
Observability

Perato Principle

The last 20% of the

work takes as long

as the first 80%

Use Step Functions where you make the money

How

Step function studio

  • Drag and drop is awesome
  • It helps you discover new possibilities
  • Exploring native integrations

DefinitionSubstitutions

SFN Workflow Sync

github.com/ljacobsson/sfn-workflow-studio-sync

Import into sls framework

functions:
   one: ...
   two: ...
resources:
  Resources:
    YourAwesomeStepFunction:
      Type: AWS::StepFunctions::StateMachine
        Properties: 
        Definition: ${file(./the-output-of-the-plugin.json)}
        DefinitionSubstitutions:
          One: !Ref OneLambdaFunction
          Two: !Ref TwoLambdaFunction
        RoleArn: !GetAtt SFNRole.Arn
    SFNRole:
    	Type AWS::Iam::Role
        Properties:
           ...YOU GOT THIS :D 

Mistakes

Don't be a localhost hero

The mega lambda

Don't put all the code in one lambda 

You don't need lambdas for everything

Rules

Start with a smoke test

test("Does my step function even work?", async () => {
	 const command = new StartExecutionCommand({
        input: JSON.stringify({ ... }),
        name: `test-invocation-${uuid()}`,
        stateMachineArn: arn
    });
    
    const result = await sfn.send(command);
    
    const execution = resolveWhenStatusComplete(response.executionArn);
    await expect(execution).toResolve()
})

Design for retries

From most common states

design your workflow so you can re-run it and get a good outcome

Each step should do only 1 thing

When using lambdas decompose your logic

Using nested step functions when it makes sense

Things I want to try

Custom UI

Step function API makes it possible to integrate workflow into your product

How possible is this in practice?

Build it with the CDK

const chain = Chain.start(openCase)
  .next(assignCase)
  .next(workOnCase)
  .next(
    isComplete
      .when(Condition.numberEquals('$.Status', 1), closeCase)
      .when(
      	Condition.numberEquals('$.Status', 0), 
        escalateCase.next(jobFailed)
       ),
  );

Thank you

Made with Slides.com