Skip to content

Instantly share code, notes, and snippets.

@ericdmoore
Last active September 13, 2021 13:01
Show Gist options
  • Save ericdmoore/39c3d02ed8a4aca3afce8120654f7183 to your computer and use it in GitHub Desktop.
Save ericdmoore/39c3d02ed8a4aca3afce8120654f7183 to your computer and use it in GitHub Desktop.
/* using ts-jest */
import { DynamoDB } from 'aws-sdk'
import localDynamo from 'local-dynamo'
import { appTable, click } from '../src/entities'
let dynamoLocal: ChildProcess
beforeAll(async () => {
// start local Dynamo Svc
// and set the internals of the Entity framework to use the locally configured reader/writer
dynamoLocal = await localDynamo.launch(undefined, 4567)
const dyn = new DynamoDB({ region: 'us-east-1', endpoint: 'http://localhost:4567' })
const localDC = new DynamoDB.DocumentClient({ service: dyn })
// mutate the appTable to use local Service and DC
appTable.DocumentClient = localDC
click.ent.table.DocumentClient = localDC
const dyn = new DynamoDB({ region: 'us-east-1', endpoint: 'http://localhost:4567' })
await dyn.createTable({
TableName: 'myTableName',
AttributeDefinitions: [
{ AttributeName: 'pk', AttributeType: 'S' },
{ AttributeName: 'sk', AttributeType: 'S' }
],
KeySchema: [
{ AttributeName: 'pk', KeyType: 'HASH' },
{ AttributeName: 'sk', KeyType: 'RANGE' }
],
BillingMode: 'PAY_PER_REQUEST',
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
}
}).promise()
await generateDataNeededForTests()
}, 45 * 1000)
afterAll(() => dynamoLocal.kill('SIGTERM'))
@ericdmoore
Copy link
Author

I think this will work for most people following the opinions laid out in the single-table design....

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