Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
atomic-execution-control
Advanced tools
Ensures atomic executions across AWS services using DynamoDB to prevent race conditions in distributed applications.
AtomicExecutionControl
is a Python library crafted to address the complexities of ensuring atomic operations across distributed applications, particularly those deployed on AWS services like Lambda, Fargate, and EC2. By leveraging DynamoDB, this library offers a robust mechanism to prevent concurrent executions, thus mitigating race conditions and duplicate processing risks. Whether you're handling event-driven workflows, orchestrating microservices, or ensuring data integrity across distributed systems, AtomicExecutionControl
simplifies state management and execution coordination, making your applications more reliable, efficient and most important 'atomic'.
Get up and running with AtomicExecutionControl
in just a few steps:
pip install atomic_execution_control
Set up a DynamoDB table in AWS with a primary key.
Use the following snippet to ensure atomic execution in your project:
from atomic_execution_control import AtomicExecutionControl
# Initialize with your DynamoDB table details
aec = AtomicExecutionControl(table_name="YourTable", primary_key="YourKey")
# Start controlling execution atomically
A DynamoDB table set up for tracking execution statuses.
AtomicExecutionControl
can be configured with the following parameters during initialization:
table_name
(required): The name of the DynamoDB table used for tracking execution.primary_key
(required): The primary key attribute name in your DynamoDB table.region_name
(optional, default="eu-west-1"
): The AWS region where your DynamoDB table is located.endpoint_url
(optional): Custom endpoint URL, useful for local testing with DynamoDB Local.delete_items_finished_or_old
method:
wait_other_instances_finish
method:
Below is a quick example to help you get started:
from atomic_execution_control import AtomicExecutionControl
import os
# DynamoDB table and primary key
TABLE_NAME = 'YourDynamoDBTableName'
PRIMARY_KEY = 'YourPrimaryKey'
# Test also in your local environment
# verify the endpoint_url, this url "http://localhost:8000" is also valid.
endpoint_url = "http://docker.for.mac.localhost:8000/" if os.environ.get("AWS_SAM_LOCAL") else None
# Initialize AtomicExecutionControl
aec = AtomicExecutionControl(
table_name=TABLE_NAME,
primary_key=PRIMARY_KEY,
region_name="eu-west-1",
endpoint_url=endpoint_url
)
# In case you already log into an specific AWS account via AWS Single Sign-On (SSO)
# you can send the profile_name parameter as follow.
profile_name = 'AwsProfileName'
aec = AtomicExecutionControl(
table_name=TABLE_NAME,
primary_key=PRIMARY_KEY,
region_name="eu-west-1",
endpoint_url=endpoint_url,
profile_name=profile_name
)
# Assume you have an event-driven architecture where multiple events
# could trigger the same task
date_to_run = '2024-01-01'
# delete items in Dynamo for old executions
aec.delete_items_finished_or_old(keys=[date_to_run], item_execution_valid_for=20)
# write in Dynamo the date_to_run and block other executions to the same key
result = aec.write_atomically_a_key(key=date_to_run)
if result:
# Process the event
print("Lock acquired, proceeding with task.")
## run_your_etl(date_to_run)
# Remember to update the status to 'finished' after completing your task
aec.update_status(key=date_to_run)
else:
# If lock couldn't be acquired, another instance is already processing the task
print("Task already in progress by another instance.")
# wait until other instances with the same key finish
aec.wait_other_instances_finish(keys=[date_to_run])
Encountering issues or have questions about integrating AtomicExecutionControl
? We're here to help!
AtomicExecutionControl
better. Don't hesitate to reach out with ideas for improvements or new features!Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Ensures atomic executions across AWS services using DynamoDB to prevent race conditions in distributed applications.
We found that atomic-execution-control demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.