Ref: https://learn.cantrill.io/courses/1820301/lectures/41301398
AWS Lambda Limitations
- Reminder: Lambda is FaaS with 15-mins max execution time… → don't try to put a full app inside a Lambda function!
- Functions can be chained together (simulate stateful apps)… but generally a bad idea!
- 👎 Scales very poorly!
- Lambda's RTEs are stateless!
- Data & environments cleaned after each function execution
- ❗ These Lambda limitations were designed purposefully!
- 💡 No product is a perfect fits-all, it's important to understand what a product was designed for, and where to use it
AWS Step Functions - Key Concepts State Machines
- 🔧 Manage long-running, serverless workflows
- Workflows defined with State Machines
- Addresses some limitations of Lambda (e.g. max execution time)
- Example of a good fit: retail order in Amazon.com
- It can take hours or days to process an order, with lots of different things happening in between
- Lambdas can't wait for so long… we require a long-running workflow
- Types of workflows:
- Standard Workflow (Default)
- Maximum duration = 1 year → long-running workflow
- Express Workflow
- Maximum duration = 5 minutes
- Can rerun failed operations more easily
- Use case: high volume & highly transactional event-processing workloads (need more processing guarantees)
- e.g. data processing or ML workflows
AWS Step Functions - State Machine (SM)
- 🔧 State Machine = base entity of AWS Step Functions
- Serverless workflow: START → [STATES] → END
- States take in data, modify data, and output data
- SM performs activity or flow
- Lots of individual components → SM maintains idea of data between states
- Complex workflows involving several AWS services
- IAM roles used for permissions → SM assumes role while running
- SM can be started via APIGW, IoT rules, EventBridge, Lambda… even manually
- Generally used for Backend processing
- Amazon States Language (ASL)
- Language used to create JSON templates that define SM state machines
- Create/export SMs
Examples of States in a Step Functions SM
- States that control flow inside a State Machine:
SUCCEED
& FAIL
→ end states
WAIT
→ waits for a certain period, or until a specific date & time
CHOICE
→ SM takes a different path depending on input
PARALLEL
→ Create parallel branches within SM
MAP
→ Accept a list of things (e.g. list of orders). For each item in list, this state performs action(s) on that item