AWS Lambda Finite State Machines

A Python framework for developing finite state machine-based workflows on AWS Lambda.

View project on GitHub
« Running Locally Running on AWS Step Functions »

Running on AWS

Build and Deploy Lambda Function Code

Build .ZIP

Build a .zip file containing you application code. For example, to build the aws-lambda-fsm example applications you can do the following:

$ workon aws-lambda-fsm-workflows
(aws-lambda-fsm)[aws-lambda-fsm-workflows (master)]$ make build
  ...
  adding: yaml/serializer.py (deflated 78%)
  adding: yaml/tokens.py (deflated 78%)

If you have written a custom application that brings in aws-lambda-fsm as a module, you will have to ensure that pyyaml and (optionally) python-memcached are included in your .zip file.

Upload to S3

S3 Upload

Configure AWS Services

Setup ~/.aws/credentials

$ cat ~/.aws/credentials
# Will expire on 2016-03-02T17:22:44Z
aws_access_key_id = ...
aws_secret_access_key = ...
aws_security_token = ...
aws_session_token = ...

Setup ~/.aws/config

$ cat ~/.aws/config
[default]
region=us-east-1
output=json

Create Kinesis Stream

$ workon aws-lambda-fsm
$ python tools/create_kinesis_stream.py --kinesis_num_shards=##

Kinesis

Create DynamoDB Tables

$ workon aws-lambda-fsm
$ python tools/create_dynamodb_table.py --dynamodb_read_capacity_units=## --dynamodb_write_capacity_units=##

DynamoDB

Create Memcache/Redis

TODO:

Create and Configure the Lambda Function

Code

Lambda S3

Handler

Configure the Lambda function handler as main.lambda_handler

Lambda Handler

Event Sources

Configure the Lambda function with three event sources

  1. Kinesis Stream

Kinesis Source

  1. DynamoDB Update

Kinesis Source

  1. CloudWatch Timer

Kinesis Source

IAM

Configure the Lambda function with a role like the following:

IAM

Start a State Machine

You can use the start_state_machine.py script to start machines on AWS as well:

$ workon aws-lambda-fsm-workflows
$ python tools/start_state_machine.py --machine_name=tracer
« Running Locally Running on AWS Step Functions »