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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file run-dynamodblocal-0.2.0.tar.gz.

File metadata

  • Download URL: run-dynamodblocal-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.9

File hashes

Hashes for run-dynamodblocal-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7e3a6fc888ddb59396704bc09b04d9f0ffa300e76f80adc43550a32b489ac0a5
MD5 def35d4b2ce29ed7bd71ee220b878ffc
BLAKE2b-256 aede8ed4514233852e79aa684a1acf2b95298f463459924d738416e948dbf3f2

See more details on using hashes here.

File details

Details for the file run_dynamodblocal-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: run_dynamodblocal-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.9

File hashes

Hashes for run_dynamodblocal-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9913ed8965b1712f87430ec62476a23bc58db0ce9993878fd30ebf22745408d
MD5 225b19d0a5c3c5132383aaf7924d711e
BLAKE2b-256 646d9327fa96e4497ac1c97f98ac490efc44e53cb517fba8849cad0d622eaae7

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