Skip to main content

Remove garbage items from DynamoDB tables

Project description

DynamoDB Garbage Collector

Version

The DynamoDB Garbage Collector is a Python library that allows you to delete garbage items in DynamoDB tables.

Table of Contents

Installation

To install the DynamoDB Garbage Collector, use pip:

$ pip install dynamodb-garbage-collector

Usage

The DynamoDB Garbage Collector currently provides a single function called purge_orphan_items, which allows you to delete orphan items in a child table that reference a non-existent item in a parent table. If optional timestamp attributes are provided only will be delete orphan items earlier than a specified maximum time (by default, one hour ago).

To use purge_orphan_items, you need to provide the following parameters:

  • logger: a logger object to log messages during the execution of the function.
  • region: the AWS region where the parent and child tables are located.
  • parent_table: the name of the parent table.
  • child_table: the name of the child table.
  • key_attribute: the name of the key attribute for both tables.
  • child_reference_attribute: the name of the reference attribute in the child table.
  • max_workers (optional): the maximum number of workers to use for concurrent operations. If not provided, a default value of 100 will be used.
  • timestamp_attribute (optional): the name of the attribute that contains the timestamp of the records in the child table. If not provided, timestamp will not be taken into account when deleting items.
  • timestamp_format (optional): the format of the timestamp attribute. If not provided, timestamp will not be taken into account when deleting items.

Here is an example of how to use the purge_orphan_items function:

import logging
from dynamodb_garbage_collector import purge_orphan_items

# Set up the logger
logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)

# Set the AWS region where the parent and child tables are located
region = 'eu-west-1'

# Set the names of the parent and child tables, and the key and reference attributes
parent_table = 'ParentTable'
child_table = 'ChildTable'
key_attribute = 'id'
child_reference_attribute = 'parentId'

# Set the maximum number of workers
max_workers = 50

# Set the name of the timestamp attribute and the timestamp format
timestamp_attribute = 'createdAt'
timestamp_format = '%Y-%m-%dT%H:%M:%S.%fZ'

# Call the function
purge_orphan_items(logger, region, parent_table, child_table, key_attribute, child_reference_attribute, max_workers, timestamp_attribute, timestamp_format)

Contributing

We welcome contributions to the DynamoDB Garbage Collector. To contribute, please fork the repository and create a pull request with your changes.

License

The DynamoDB Garbage Collector is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamodb_garbage_collector-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file dynamodb_garbage_collector-1.0.0.tar.gz.

File metadata

  • Download URL: dynamodb_garbage_collector-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.10 Linux/5.15.0-56-generic

File hashes

Hashes for dynamodb_garbage_collector-1.0.0.tar.gz
Algorithm Hash digest
SHA256 34f2a5e01b8d1f25a4a4ce1d4255eb57c1ce0dd5f585efa33b743d3a2b03f123
MD5 e8042d8b59e2e4ee8d6af465e8e9f3f7
BLAKE2b-256 5d0561762c2160e14db53134ec707c2f2853d830893e046ce13f6a208d540836

See more details on using hashes here.

File details

Details for the file dynamodb_garbage_collector-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamodb_garbage_collector-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1476106d20cf46ea090fffaf454e1ee664109b028e5ff033f8d8745aa1b87f7e
MD5 8589705e42c4fac6e3edb47872719df3
BLAKE2b-256 73a81422c2f8d4b96043d2bb06e76e5b5e918bbd83e18cf0c1417d4373c473cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page