Getting started
Install
Install AWS Emulator 1.0.290 or later as AWS describes, so aws-emulator is on PATH, then the package:
npm i -D aws-emulator-launchpnpm add -D aws-emulator-launchyarn add -D aws-emulator-launchTIP
aws-emulator-launch is ESM only, and runs in Node.js 22.12 or later.
Start one emulator for the run
Start it in a hook that runs once, and stop it in the matching hook. With mocha-chain, a before at the top level of a module is a root hook, run once per process:
import { DynamoDB } from '@aws-sdk/client-dynamodb';
import { awsClientConfig, launchAwsEmulator } from 'aws-emulator-launch';
import { before } from 'mocha-chain';
export const withDynamoDb = before(async () => {
const emulator = await launchAwsEmulator();
const dynamodb = new DynamoDB(awsClientConfig(emulator));
return { emulator, dynamodb };
});
withDynamoDb.after(async ({ emulator, dynamodb }) => {
dynamodb.destroy();
await emulator.stop();
});awsClientConfig() gives the client the emulator's endpoint, region and keys, trusts only its certificate authority, and fixes every setting the SDK would otherwise read from your environment or ~/.aws/config, such as AWS_USE_FIPS_ENDPOINT.
The emulator starts empty, so tests create the tables and queues they use. Giving each a name of its own means they don't need to clean up after each other.
If aws-emulator isn't installed, launchAwsEmulator rejects with an AwsEmulatorNotRunError that links AWS's install guide. A repository that installs the emulator for you (in a devcontainer, say) can catch it and say how to get it there instead.