Skip to main content

Configure

AWS SDK

Dynamode uses @aws-sdk/client-dynamodb package under the hood. Therefore, it is required to authenticate with AWS so Dynamode can make requests to DynamoDB.

caution

Authenticate as early in the application life cycle as possible to prevent errors. Dynamode needs valid AWS credentials to make requests to DynamoDB.

Authenticate with environment variables

You can use environment variables to authenticate.

AWS_ACCESS_KEY_ID = "key-id"
AWS_SECRET_ACCESS_KEY = "secret"
AWS_REGION = "region"
import Dynamode from 'dynamode/dynamode';
// Access DynamoDB instance
const ddb = Dynamode.ddb.get();

Authenticate programmatically

info

This is recommended way of authenticating with AWS.

You can also instantiate DynamoDB programmatically, pass the instance to Dynamode in order to use it.

import { DynamoDB } from '@aws-sdk/client-dynamodb';
import Dynamode from 'dynamode/dynamode';

// Instantiate DynamoDB
const ddb = new DynamoDB({
credentials: {
accessKeyId: 'key-id',
secretAccessKey: 'secret',
},
region: 'region',
});

// Pass DynamoDB instance to Dynamode
Dynamode.ddb.set(ddb);

Authenticate locally

To setup DynamoDB locally. Check out docker-compose.yml file and examples/ catalog. Once DynamoDB local server is running on 'http://localhost:8000' you can use the following command.

import Dynamode from 'dynamode/dynamode';

// Local DynamoDB instance
const ddb = Dynamode.ddb.local();

In case your local DynamoDB server is running at a different url you can pass that in as an argument.

const ddb = Dynamode.ddb.local('http://localhost:2137');

Read more about Dynamode class here.