Skip to main content

Run an in-memory DynamoDBLocal for testing

Project description

Run-DynamoDBLocal

AWS makes DynamoDBLocal -- a service that mirrors the API of DynamoDB and runs locally -- available to their customers for testing purposes. This Python packages facilitates running that service as a subprocess of the testing harness.

Install

$ pip install 'run-dynamodblocal[boto3]'

Leave off the [boto3] if you don't intend to use this package's ability to patch boto3.

Usage

Quickstart

With thanks to ncoghlan:

import boto3_mocking
from contextlib import ExitStack
import os.path
import run_dynamodblocal
import unittest

# If patching isn't engaged when the run_dynamodblocal context is entered, an
# exception will be thrown
boto3_mocking.engage_patching()

class MyTest(unittest.TestCase):
    def setUp(self):
        with ExitStack() as resources:
            dynamodblocal_path = os.path.expanduser(
              # wherever you keep the unpacked service binaries
              '~/Downloads/dynamodb_local_latest'
            )
            resources.enter_context(
                run_dynamodblocal.rddbl.patched_into_boto3(dynamodblocal_path)
            )
            
            # Enter any other contexts for this test class...
            
            addCleanup(resources.pop_all().close)
    
    # Define test methods here

Diving Deeper

This package provides two different context managers which run the DynamoDBLocal service -- one of which integrates with boto3 to automatically redirect the dynamodb service to this DynamoDBLocal instance. The DynamoDBLocal started will use the -inMemory flag, so it does not persist on disk after the test run is over and doesn't waste testing time committing information to disk.

Context Manager Description
run_dynamodblocal.in_subprocess The most fundamental; runs the server and returns the port number as the context value
run_dynamodblocal.patched_into_boto3 Runs the server and patches it into the boto3 library

It also provides the run_dynamodblocal.LocalDbOps class, which supports refreshing the database schema and populated data based on a Serverless configuration and some basic JSON-type data.

Contributing

  1. Fork it on GitHub (https://github.com/rtweeks/run-dynamodblocal)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request (on GitHub)

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

run-dynamodblocal-0.2.0.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distribution

run_dynamodblocal-0.2.0-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

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