Repository navigation
New module DynamoDB - #1613
New module DynamoDB#1613stschulte wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
Thanks @stschulte! DynamoDB is on our list of missing modules (#1575).
- Keep
-inMemoryin the command whatever options are set. TodaywithSharedDB()on its own switches to an on-disk database. - Drop
withInMemory()(already the image default) andwithDbPath()(can't be combined with in-memory). - Set the wait strategy in the constructor.
- Each test should fail if its option never reaches the container. The in-memory and telemetry tests pass either way.
- The branch conflicts with
main. Please rebase and regenerate the lockfile withnpm 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]; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
-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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Nit: describe and it are globals, like expect. The other modules don't import them.
|
|
||
| ### Connect to local endpoint | ||
|
|
||
| In order to use a DynamoDB Client we have to specify |
There was a problem hiding this comment.
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().
| <!--codeinclude--> | ||
| [](../../packages/modules/dynamodb/src/dynamodb-container.test.ts) inside_block:connectClientConfig | ||
| <!--/codeinclude--> | ||
|
|
There was a problem hiding this comment.
Nit: whitespace-only line.
Adds a new
DynamoDBContainerto help running a local AWS DynamoDB container as described in the docs