Code Monkey home page Code Monkey logo

sbt-dynamodb's Introduction

sbt-dynamodb

Support for running DynamoDB Local in tests.

MIT license Download

Installation

Add the following to your project/plugins.sbt file:

For sbt 1.0:

addSbtPlugin("com.localytics" % "sbt-dynamodb" % "2.0.2")

For sbt 0.13.5+

addSbtPlugin("com.localytics" % "sbt-dynamodb" % "1.5.5")

sbt 0.13.6+ is supported, 0.13.5 should work with the right bintray resolvers

Usage

To use DynamoDB Local in your project you can call start-dynamodb-local and stop-dynamodb-local directly in sbt.

Configuration

To have DynamoDB Local automatically start and stop around your tests

startDynamoDBLocal := startDynamoDBLocal.dependsOn(compile in Test).value
test in Test := (test in Test).dependsOn(startDynamoDBLocal).value
testOnly in Test := (testOnly in Test).dependsOn(startDynamoDBLocal).evaluated
testOptions in Test += dynamoDBLocalTestCleanup.value

To download the DynamoDB Local jar to a specific location ("dynamodb-local" is the default)

dynamoDBLocalDownloadDir := file("my-dir")

To use a specific version ("latest" is the default DynamoDB version to download and run)

dynamoDBLocalVersion := "2014-10-07"

If the "latest" version is being used, specify how old the downloaded copy should be before attempting a new download (default is 2 days)

import scala.concurrent.duration._
dynamoDBLocalDownloadIfOlderThan := 2.days

To specify a port other than the default 8000

dynamoDBLocalPort := 8080

To override the default JVM heap size (specified in MB)

dynamoDBLocalHeapSize := Some(1024)

The default for the DynamoDB Local instance is to run in "in-memory" mode. To use a persistent file based mode you need to set both the data path & turn off in-memory. The plugin will fail to overwrite an existing db file at this path.

dynamoDBLocalInMemory := false
dynamoDBLocalDBPath := Some("some/directory/here")

The default for DynamoDB Local instance is to use a separate file for each credential and region. To allow all all DynamoDB clients to interact with the same set of tables regardless of their region and credentials enable "shared db" mode.

dynamoDBLocalSharedDB := true

The default on stop is to cleanup any data directory if specified. This can be changed using

dynamoDBLocalCleanAfterStop := false

Debugging db Contents

Configure your app to persist to disk:

dynamoDBLocalInMemory := false
dynamoDBLocalDBPath := Some("some/directory/here")

Once you have completed some operation involving dynamo, you can inspect the contents with sqlite3. Example:

$ sqlite3 /tmp/dynamo/test/AXAVAXAJUNK_us-east-1.db "select ObjectJSON from \"table\"" |  jq '.device_id,.env'
{
  "N":"123456789"
},
{
  "S":"Production"
}

Scopes

By default this plugin lives entirely in the Global scope. However, different settings for different scopes is possible. For instance, you can add the plugin to the Test scope using

inConfig(Test)(baseDynamoDBSettings)

You can then adjust the settings within the Test scope using

(dynamoDBLocalDownloadDir in Test) := file("in-test/dynamo-db")

and you can execute the plugin tasks within the Test scope using

sbt test:start-dynamodb-local

Similarly, you can have the plugin automatically start and stop around your tests using

startDynamoDBLocal in Test := (startDynamoDBLocal in Test).dependsOn(compile in Test).value
test in Test := (test in Test).dependsOn(startDynamoDBLocal in Test).value
testOnly in Test := (testOnly in Test).dependsOn(startDynamoDBLocal in Test).evaluated
testOptions in Test += (dynamoDBLocalTestCleanup in Test).value

Thanks

This work is based on the Maven Plugin for DynamoDB.

The initial implementation was developed by Graham Rhodes.

sbt-dynamodb's People

Contributors

bdarfler avatar brentax avatar grahamar avatar jeffwilde avatar joshragem avatar jsolmon avatar philwills avatar sfindeisen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.