Skip to content

elfiyang16/saga-pattern-by-the-sea

Repository files navigation

SAGA BY THE SEA -- A SERVERLESS SAGA PATTERN WITH STEP FUNCTION

diagram statemachine

AWS Services

  • Lambda
  • API Gateway
  • Stepfunctions
  • DynamoDB
  • SNS
  • SQS

Architecture is provisioned with CloudFormation

Deployment and Test

  • Set env var:
PROJECTNAME=SAGA_ORDER_PROCESS
YOURNAME=XXX
[email protected]
  • Create the S3 bucket for the lambda functions:aws s3 mb s3://$PROJECT

  • Install python package

cd lambda/layer/python
pip install -r requirements.txt -t .
  • Upload local artifacts
aws cloudformation package \
    --template-file stepfunction.yml \
    --s3-bucket $PROJECT \
    --output-template-file packaged.yml

aws cloudformation deploy \
    --stack-name $PROJECT \
    --region eu-west-1 \
    --template-file packaged.yml \
    --capabilities CAPABILITY_NAMED_IAM \
    --output text \
    --parameter-overrides \
        NotifyEmail=$YOUREMAIL
  • To trigger a run
aws lambda invoke \
    --function-name TestSfnFunction \
    --region eu-west-1 \
    --payload '{}' \
    response.json

You can have your own data sample or use the example provided:

{
  "order_id": "40063fe3-56d9-4c51-b91f-71929834ce03",
  "order_date": "2019-12-01 12:32:24.927479",
  "customer_id": "2d14eb6c-a3c2-3412-8450-239a16f01fea",
  "items": [
    {
      "item_id": "0123",
      "qty": 1.0,
      "description": "item 1",
      "unit_price": 12.99
    },
    {
      "item_id": "0234",
      "qty": 2.0,
      "description": "item 2",
      "unit_price": 41.98
    },
    {
      "item_id": "0345",
      "qty": 3.0,
      "description": "item 3",
      "unit_price": 3.5
    }
  ]
}

About

aws step function implemented saga pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published