Skip to content

Latest commit

 

History

History
150 lines (105 loc) · 4.21 KB

README.md

File metadata and controls

150 lines (105 loc) · 4.21 KB

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.