TechWriterDev
  • Cloud
    • AWS
      • 00_Doubts
      • CloudPractitioner
        • Cloud Computing
        • AWS Global Infrastructure
        • Introduction to AWS EC2
        • Elastic load balancer(ELB)
        • 04_Messaging_Queuing
        • Aditional Computing Service
        • Accessing AWS resources
        • AWS Networking
        • Storage
        • Amazon Database Solutions
        • Monitoring Tools
        • AWS Security
        • Distributed Denial Of Service Attacks
      • DeveloperAssociate
        • References
        • AWS DVA-C02 Services Index
        • Services
          • 00_IAM
            • Identity and Access Management (IAM)
            • Account Protection Mechanisms
            • Access Mechanism of AWS Resources
            • Security Tools
            • Responsibility Model
            • Advanced Concepts
          • 01_EC2
            • Elastic Compute Cloud (EC2)
            • EC2 Volume Types
            • Amazon Machine Image (AMI)
            • AWS charges for IPv4 address
          • 02_SecurityGroups
            • Security Groups
          • 03_Elastic_LoadBalancing
            • Terminology
            • Elastic load balancer
            • Features
            • Basics
          • 04_AutoScaling
            • Auto Scaling
          • 05_RDS
            • Relational Database Service (RDS)
            • Aurora
            • Security
            • RDS Proxy
          • 06_ElastiCache
            • Cache
            • Cache Offerings
          • 07_Route53
            • Basics of DNS
            • Route 53
          • 08_VPC
            • Virtual Private Cloud (VPC)
          • 09_S3
            • Simple Storage Service (S3)
            • S3 Features
            • S3 Encryption
            • S3 Features
            • S3 Bucket Policy and IAM Policy
          • 10_ECS
            • Elastic Container Service (ECS)
            • Elastic Container Registry (ECR)
            • AWS Copilot
          • 11_EKS
            • Elastic Kubernetes Service (EKS)
          • 12_SDK_CLI_Tips
            • Access AWS Resources
          • 13_CloudFront
            • Cloud Front
          • 14_Messaging
            • Simple Queue Service (SQS)
            • Simple Notification Service (SNS)
            • Fan Out Pattern
            • Kinesis
            • Compare and Contrast
          • 15_ElasticBeanStalk
            • Elastic Beanstalk
          • 16_CloudFormation
            • CloudFormation
            • Dynamic References
          • 17_Monitoring
            • AWS Monitoring
            • AWS CloudWatch
            • CloudWatch Alarms
            • Synthetics Canary
            • Amazon EventBridge (formerly CloudWatch Events)
            • X-Ray
            • OpenTelemetry
            • CloudTrail
          • 18_Lambda
            • Lambda
            • Lambda Integrations
            • Configuring Lambda
            • Lambda Layers
          • 19_API_Gateway
            • API Gateway
            • API Gateway Integrations
          • 20_DynamoDB
            • DynamoDB
            • Operations
            • Indexes
            • DynamoDB Accelerator (DAX)
            • DynamoDB Streams
            • Transactions
            • Integrations
          • 21_CICD
            • CICD
            • CodeCommit
            • CodePipeline
            • CodeBuild
            • CodeDeploy
            • CodeArtifact
            • CloudGuru
          • 22_SAM
            • Serverless Application Model (SAM)
          • 23_CDK
            • Cloud Development Kit (CDK)
          • 24_StepFunctions
            • Step Functions
            • Types of step function
          • 25_AppSync
            • AppSync
          • 26_Amplify
            • Amplify
          • 27_STS
            • Security Token Service (STS)
          • 28_DirectoryService
            • Active Directory
          • 29_KMS
            • Encryption
            • KMS API
            • Features
            • Cloud Hardware Security Module (HSM)
          • 30_SSM_Store
            • SSM Parameter Store
          • 31_SecretsManager
            • Secrets Manager
          • 32_Cognito
            • Cognito
      • Questions
        • AWS_Region
        • EC2
        • IAM
  • Database
    • MongoDb
      • Mongo db Basics
      • Mongo DB Atlas
      • Document
      • Import-Export based on Data Format
      • Mongo Shell Commands
      • Query Operators
      • Indexes
      • Upsert
      • MongoDB Aggregation Framework
      • Aggregation Framework Operators
    • PostgreSQL
      • POSTGRE SQL DataTypes
      • About table
      • Constraints
  • Technologies
    • RabbitMQ
      • RabbitMQ Concepts
      • Introduction to Exchanges
      • Introduction to Queues
    • Terraform
      • 00_Introduction
      • Configuration blocks
      • Commands
      • Variables
      • Terraform Cloud
      • Modules
  • Languages
    • Java
      • Logging
        • Getting Started
      • 00_Core
        • 00_Basics
          • Java Vs C++
          • Object oriented principles
          • Steps to compile a java program
          • JVM Internals
          • Understanding Java Development Kit
          • What is JIT Compiler?
          • Java data types
          • 07_identifiers_type_conversion
          • 08_references_and_packages
          • Steps for attaching scanner
        • Concurrency
          • 00_Threads
            • Threads
          • 01_ExecutorFramework
            • Executor Framework
            • Asynchronous Computation
      • 01_Backend
        • 01_HttpAndWebServerBasics
          • HTTP
          • Content Type
          • Web Server
        • 02_J2EE_Basics
          • J2EE_Basics
          • Why HttpServlet classs is declared as abstract class BUT with 100 % concrete functionality ?
        • 03_TomCatAndSession
          • What is a Session?
          • WebContainer
        • 04_PageNavigation
          • Cookies Additional Information
          • Page Navigation Techniques
        • 05_AboutServlet
          • CGI v/s Servlet
          • Executor Framework
          • Servlet Life cycle
          • SERVLET CONFIG
          • Servlet Context
          • Servlet Listener (web application listener)
        • 08_SpringBoot
          • Spring Boot
          • Some common annotations used in spring eco system
        • 09_SpringDataJPA
          • Spring Data JPA
        • Java_Language_Changes
          • JDK enhancement tracking reference
        • 06_ORM_Hibernate
          • readmes
            • Hibernate
            • Advantages of Hibernate
            • Hibernate Caching
            • Hibernate API
            • Hibernate Query API
            • Hibernate Annotations and JPQL
            • Entity and Value Type
        • 07_SpringFramework
          • bean_validation
            • Bean Validation
          • core
            • readme
              • Spring
              • Spring Framework Modules
              • Spring MVC Request flow
              • Dependency Injection
              • Spring Beans
              • 06_Spring_Framework_Annotations
      • 03_Tools
        • Maven
          • Maven
  • SoftwareEngineering
    • DesignPatterns
      • Notes
        • Basics
        • OOP
        • SOLID Principles
        • 03_Creational
          • Abstract Factory (aka Kit)
          • Builder
          • Factory Method (aka Virtual constructor)
          • Prototype
          • Singleton
        • 04_Structural
          • Adapter (aka Wrapper)
          • Bridge (aka Handle | Body)
          • Composite
          • Decorator (aka Wrapper)
          • Facade
          • Flyweight
          • Proxy (aka Surrogate)
        • 05_Behavioral
          • Chain of Responsibility
          • Command (aka Action | Transaction)
          • Iterator (aka Cursor)
          • Observer (aka Publish-Subscribe | Dependents)
          • Strategy (aka Policy)
    • Principles
      • REST
        • REST
  • Tools
    • Containers
      • Docker
        • Docker
        • Docker Image
        • Commands
        • Compose
        • Best Practices
      • Kubernetes
        • Kubernetes
    • VCS
      • Git
        • Quick reference of useful Git commands
Powered by GitBook
On this page
  • Icon
  • About
  • Task
  • States
  • Activity task
  • Wait for task token
  • Sample flow diagram
  • Error handling
  • Retry
  • Catch
  1. Cloud
  2. AWS
  3. DeveloperAssociate
  4. Services
  5. 24_StepFunctions

Step Functions

Previous24_StepFunctionsNextTypes of step function

Last updated 4 months ago

Icon

Step Function Icon

About

  • It is an orchestrator service to manage workflows as state machine.

  • Workflow is written in json format using Amazon State Language (ASL) .

  • It provides visualization of the workflow and execution of workflow as well as history of execution.

  • To start workflow we can use SDK API call, API Gateway, EventBridge or invoke manually from Management Console.

Task

  • State machine comprises of task.

  • Task state is a unit of work that is executed to perform some work in state machine.

  • Task that could be defined in task state are,

    • Invoking a lambda function

    • Run an AWS batch job

    • Run an ECS task and wait for it to complete

    • Insert an item from DynamoDb

    • Publish message to SNS and SQS

    • Launch another step function workflow

  • Task could also be running one activity.

    • Activity could be running an EC2 machine, ECS task, on-premise

    • Acivities poll the step functions for work.

    • Once work is received, the task is execution by polling system and result is send back to step function.

States

State
Description

Task state

A single unit of work to be performed by your state machine

Choice state

Test for a condition to send to a branch

Fail or Succeed state

Stop execution with failure or success

Pass state

Simply pass its input to its output or inject some fixed data without performing any work

Wait state

Provide a delay for certain amount of time or until a specified date/time

Map state

Dynamically iterate steps

Parallel state

Begin Parallel branches of execution

Activity task

  • Enables you to have the task work performed by an ActivityWorker.

  • ActivityWorker apps can be running on EC2, Lambda etc.

  • These workers poll for a task using GetActivityTask API, after ActivityWorker completes its work, it sends a response of it success/failure using SendTaskSuccess or SendTaskFailure API.

  • Task can be kept active

    • By configuring TimeoutSeconds.

    • Periodically send a heartbeat from ActivityWorker using SendTaskHeartBeat with the time you set in HeartBeatSeconds.

  • By configuring a long TimeoutSeconds and actively sending a hearbeat, ActivityTask can wait upto 1 year.

Wait for task token

  • Allows to pause the step function during a task until a task token is returned.

  • Task might wait for other AWS services, human approval, 3rd party integration etc.

  • Append .waitForTaskToken to the resource field to tell Step Functions to wait for the task token to be returned.

  • In the message body input pass the task token.

  • Once task is completed the token is passed back in response through SendTaskSuccess or SendTaskFailure API call.

  • Task will pause until it receives the task token back with SendTaskSuccess or SendTaskFailure API call.

Sample flow diagram

Error handling

  • Step functions executes many small task.

  • Error handling should happen outside of step funtion.

  • Error could be

    • State machine has definition issues (for example no rule matching in a Choice state)

    • Task failure such as (exception in lambda functions).

  • Use Retry and Catch in the State Machine to handle errors instead of the Application code.

  • Predefined error codes are present

    Error code
    Description

    States.ALL

    Matches any error name

    States.Timeout

    When task takes longer than TimeoutSeconds or no heartbeat received

    States.TaskFailed

    Execution failure

    States.Permissions

    Insufficient permission to execute code

  • The state may report its own errors.

Retry

  • Allows you to define what happens on errors and customize retry parameters like back-off rate, max attempts, interval-seconds.

  • By default max-attempt is 3.

  • Once max-attempt is reached the Catch kicks in.

Catch

  • Allow you to define how to handle error once they occur or if retries are exhausted.

  • The catch block can have ResultPath key, which can have $.error as value, to pass on the error to next task as input.

    • Typically ResultPath have result of current task, which can be passed to the next task.

Wait for task token
Retry
Catch Block