Skip to content

Commit

Permalink
DynamoDB Local URL and Region can be set as environment variables (pr…
Browse files Browse the repository at this point in the history
…eviously were hardcoded)
  • Loading branch information
sgalushin committed Aug 19, 2021
1 parent c8ec036 commit 76b9fa1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ To run all tests execute `make test` from the project root directory.
To test that package execute `npm run test` from that package's directory.

All unit tests require DynamoDB Local to be available on `localhost:8000`. To run it in Docker use `docker run -p 8000:8000 -d amazon/dynamodb-local`. Unit tests create randomly named DynamoDB tables and don't delete them after the test (for performance reasons). The expectation is that the DynamoDB Local container should be easily discarded. Running multiple iterations of tests on the same container is fine as a chance for a collision in table names is extremely unlikely.

You can change the default location for DynamoDB Local by running tests with the following environment variables:

| Variable Name | Example & Default Value (ie. without the variable being set) | Description |
|---|---|---|
|DYNAMODB_TEST_REGION | eu-west-1 | The value doesn't matter for local DynamoDB Instance (but it cannot be empty) |
| DYNAMODB_TEST_URL | http://localhost:8000 | |



### End-to-End tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import KSUID from "ksuid";
import { CreateTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb";

const LOCAL_REGION = "eu-west-1"; // doesn't matter for local DynamoDB, it just needs to be set
const LOCAL_ENDPOINT = "http://localhost:8000";
const LOCAL_REGION = process.env.DYNAMODB_TEST_REGION ?? "eu-west-1"; // doesn't matter for local DynamoDB, it just needs to be set
const LOCAL_ENDPOINT = process.env.DYNAMODB_TEST_URL ?? "http://localhost:8000";

export const createLocalTable = async () => {
const tableName = `product-catalog-${(await KSUID.random()).string}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CreateTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb";
import KSUID from "ksuid";

const LOCAL_REGION = "eu-west-1"; // doesn't matter for local DynamoDB, it just needs to be set
const LOCAL_ENDPOINT = "http://localhost:8000";
const LOCAL_REGION = process.env.DYNAMODB_TEST_REGION ?? "eu-west-1"; // doesn't matter for local DynamoDB, it just needs to be set
const LOCAL_ENDPOINT = process.env.DYNAMODB_TEST_URL ?? "http://localhost:8000";

export const createLocalTable = async () => {
const tableName = `rolls-${(await KSUID.random()).string}`;
Expand Down

0 comments on commit 76b9fa1

Please sign in to comment.