💾 Archived View for capsule.adrianhesketh.com › 2020 › 12 › 04 › dynamodb-local-with-nix captured on 2023-11-04 at 11:44:31. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

-=-=-=-=-=-=-

capsule.adrianhesketh.com

home

Running DynamoDB Local with nix

I've been using Nix [0] as a package manager for a while. Rather than installing packages globally like `brew`, the idea with Nix is to have a minimal set of base packages, then to start shell sessions containing just the tools you need. This reduces the amount of cruft just sitting around on your machine.

[0]

I wanted to run a local DynamoDB for testing, but you need to have Java installed, and, of course, I don't have it installed by default.

The alternatives the documentation lists [1] are to use Maven (a Java package manager) or Docker but let's face it, if I don't like having Java installed, I'm not going to like running Docker.

[1]

I don't like it because on the Mac, it's a waste of CPU/RAM, because it runs a Virtual Machine and a daemon. You're probably wondering why I use a Mac at all, and it's something I wonder myself until I remember when I had a Linux laptop.

Fortunately, I can start a shell with Nix that just contains my base packages, plus Java to run DynamoDB instead.

nix-shell --packages jdk11

So that's fine, but I also need the DynamoDBLocal.jar file, and I want to make sure that I keep the data in my local table between runs.

Well, that's easy enough to pull together into a single script:

#!/bin/sh
if ! [ -f ./DynamoDBLocal.jar ]; then
  curl https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_latest.zip -o d.zip
  unzip d.zip
  rm d.zip
fi
mkdir -p data
nix-shell --packages jdk11 --run "java -jar DynamoDBLocal.jar -sharedDb -dbPath ./data"

Now, I can run `zsh ./dynamodb.sh` and I've got it running, but when I exit, I've not got Java installed.

More

Next

AWS CLI - authenticating with SSO

Previous

Idempotency in Lambda - 3 - Idempotent APIs

Home

home