Skip to content

Latest commit

 

History

History

app-control-concurrency-with-dynamodb-tf

Concurrency Controller - A Workflow that uses DynamoDB to implement a semaphore

This application demonstrates how to implement control concurrency in your distributed system. This helps you avoid overloading limited resources in your serverless data processing pipeline or reduce availability risk by controlling velocity in your IT automation workflows.
With this sample application, you implement a distributed semaphore using AWS Step Functions and Amazon DynamoDB to control concurrent invocations of a function in AWS Lambda.

For more workflows check https://serverlessland.com/workflows

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

  • Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
  • AWS CLI installed and configured
  • Git Installed
  • Terraform installed

How it works

The template creates a workflow to get you started in implementing control concurrency in your distributed system.

statemachine

All provisioned resources will have a name prefix set to CC by default. It can be changed by supplying the variable NamePrefix value to Terraform. The default region is us-east-1, it can also be changed using the variable region. The default Semaphore lock name is MySemaphore, it can be changed using the variable LockName

Note: Variables can be supplied in different options, check the Terraform documentation for more details.

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
    git clone https://github.com/aws-samples/step-functions-workflows-collection
    
  2. Change directory to the pattern directory:
    cd step-functions-workflows-collection/app-control-concurrency-with-dynamodb-tf
    
  3. From the command line, initialize Terraform to download and install the providers defined in the configuration:
    terraform init
    
  4. From the command line, apply the configuration in the main.tf file:
    terraform apply
    
  5. During the prompts:
    • Enter yes
  6. Note the outputs from the deployment process. These contain the resource names and/or ARNs which are used for testing.

Testing

  1. Go to the AWS Step Functions Console and find the State Machine from the Terraform Output. It should be named <NamePrefix>-Test-Run100Executions

  2. Run the State Machine with any valid input. It will start 100 executions of the workflow that will control concurrency to 5 executions using semaphores.

  3. The Lambda function will simulate random failures as part of the workflow to simulate real life scenarios. In those cases the locks will be automatically cleared by the State Machine CleanFromIncomplete to prevent deadlocks.

Cleanup

  1. Change directory to the pattern directory:
    cd step-functions-workflows-collection/app-control-concurrency-with-dynamodb-tf
    
  2. Delete all created resources
    terraform destroy
  3. During the prompts:
    • Enter yes
  4. Confirm all created resources has been deleted
    terraform show

Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0