Skip to content

New module DynamoDB - #1613

Open
stschulte wants to merge 1 commit into
testcontainers:mainfrom
stschulte:new-module-dynamodb
Open

stschulte wants to merge 1 commit into
testcontainers:mainfrom
stschulte:new-module-dynamodb

Conversation

@stschulte

Copy link
Copy Markdown

Adds a new DynamoDBContainer to help running a local AWS DynamoDB container as described in the docs

Adds a new `DynamoDBContainer` to help running a local AWS DynamoDB
container as described [in the docs][1]

[1]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html#docker

@cristianrgreco cristianrgreco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stschulte! DynamoDB is on our list of missing modules (#1575).

  1. Keep -inMemory in the command whatever options are set. Today withSharedDB() on its own switches to an on-disk database.
  2. Drop withInMemory() (already the image default) and withDbPath() (can't be combined with in-memory).
  3. Set the wait strategy in the constructor.
  4. Each test should fail if its option never reaches the container. The in-memory and telemetry tests pass either way.
  5. The branch conflicts with main. Please rebase and regenerate the lockfile with npm install -w @testcontainers/dynamodb.

Nits: please retitle to Add DynamoDB module to match the other module PRs.


// If we pass arguments we also have to pass
// -jar DynamoDBLocal.jar
return ["-jar", "DynamoDBLocal.jar", ...command];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image's default command is -jar DynamoDBLocal.jar -inMemory. Replacing it drops -inMemory, so withSharedDB() or withDisableTelemetry() on their own silently switch to an on-disk database (the startup banner shows InMemory: false). Always pass -inMemory.

* Fore more information please read
* https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html#DynamoDBLocal.CommandLineOptions
*/
public withInMemory(): this {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-memory is already the image's default, so this option changes nothing on its own, and its test passes without it. Please drop it.

*
* @param dbPath - The path to the database file inside the container
*/
public withDbPath(dbPath: string): this {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-dbPath can't be combined with -inMemory: withInMemory().withDbPath(".") exits at startup with dbPath and inMemory cannot be set at the same time. The file also lives in the container's filesystem, so it only survives a restart of the same container. Neither the Go nor the .NET module has this option; please drop it.


constructor(image: string) {
super(image);
this.withExposedPorts(DYNAMODB_PORT).withStartupTimeout(120_000);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set the wait strategy here so users can override it. GET / returns 400 once DynamoDB Local is serving, which is what the .NET module waits on: .withWaitStrategy(Wait.forHttp("/", DYNAMODB_PORT).forStatusCode(400)).

* const client = new DynamoDBClient(container.clientConfig());
* ```
*/
public clientConfig(): DynamoDBLocalClientConfig {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop clientConfig() and its type. LocalStack and the Go and .NET DynamoDB modules only expose the endpoint, and this ties the module's public API to the AWS SDK's config shape. The return type isn't exported from index.ts either. The connectEndpoint example already shows the full client setup.

await teardown();
});

it("separates data by client by default", async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests DynamoDB Local's own behaviour. The sharedDB test already fails if -sharedDb doesn't reach the container, so this one can go.

* @param tableName - The desired table name
* @returns - Three functions: teardown, addUser, getUser
*/
async function createDummyTable(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be much smaller. DynamoDB Local returns tables as ACTIVE straight away, so the waiters aren't needed, and teardown isn't either because the container is removed after each test. The JSDoc can go too.

waitUntilTableExists,
waitUntilTableNotExists,
} from "@aws-sdk/client-dynamodb";
import { describe, it } from "vitest";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: describe and it are globals, like expect. The other modules don't import them.

Comment thread docs/modules/dynamodb.md

### Connect to local endpoint

In order to use a DynamoDB Client we have to specify

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other module pages go straight from the IMAGE line to the examples. Please drop this paragraph, and the "Connect via client config" section along with clientConfig().

Comment thread docs/modules/dynamodb.md
<!--codeinclude-->
[](../../packages/modules/dynamodb/src/dynamodb-container.test.ts) inside_block:connectClientConfig
<!--/codeinclude-->

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace-only line.

@cristianrgreco cristianrgreco added enhancement New feature or request minor Backward compatible functionality labels Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor Backward compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants