Table of Contents
Barriers and Latches are synchronisation mechanisms that enable a dependent thread to wait upon independent events.
- C++: std::barrier, std::latch
- Java: CyclicBarrier, CountDownLatch
Lambda functions depend on independent events too.
This project implements generic Event Barriers for Lambda functions. The Lambda function waits until all independent events have arrived. AWS S3 is used for state management.
Along the way, we will implement Lambda function unit tests, integration tests, and load tests for over 100 Event Barriers.
Python, an AWS account, and the AWS CLI are needed to run this project.
These AWS services are configured and deployed from the command line
-
Clone the repo
git clone https://github.com/press0/aws-eventbarrier.git
-
create a virtual environment
python -m venv venv
-
install requirements
python -m pip install -r requirements.txt
-
define event barriers in a configuration file.
{ "event-barrier-0": [ "0/0", "0/1" ], "event-barrier-1": [ "1/0", "1/1" ], "event-barrier-2": [ "2/0", "2/1", "2/2" ] }
-
build the lambda function zip file
zip function.zip eventbarrier.py config/eventbarrier.json
-
create the lambda function. Replace the 12 hash characters with your AWS account number.
aws lambda create-function --function-name eventbarrier \ --runtime python3.8 \ --zip-file fileb://function.zip \ --handler eventbarrier.lambda_handler \ --role arn:aws:iam::############:role/eventbarrier
-
update lambda function code as needed
aws lambda update-function-code \ --function-name eventbarrier \ --zip-file fileb://function.zip
-
create an S3 bucket and a prefix
aws s3 rb s3://eventbarrier
-
create an IAM policy with minimum required permissions
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "s3:GetObject", "logs:CreateLogStream", "logs:CreateLogGroup", "logs:PutLogEvents" ], "Resource": [ "arn:aws:s3:::eventbarrier/*", "arn:aws:logs:*:*:*" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": "arn:aws:s3:::eventbarrier" } ] }
-
create an IAM role
aws iam create-role \ --role-name eventbarrier --assume-role-policy-document file://config/eventbarrier-policy.json
-
create an event notification in one of two ways:
- manually; s3 console > bucket properties tab > create event notification
- automated; aws cli
aws s3api put-bucket-notification-configuration \
--bucket eventbarrier
--notification-configuration file://config/notification.json
with notification.json like:
{
"TopicConfigurations": [
{
"TopicArn": "arn:aws:sns:us-west-2:123456789012:s3-notification-topic",
"Events": [
"s3:ObjectCreated:*"
]
}
]
}
Verify lambda function logic and validate your custom event barrier configuration in eventbarrier.json
python eventbarrier_test.py
Upload files to the respective prefix of each event barrier. AWS CloudWatch verifies the event barrier conditions.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.