Skip to main content

Getting started

Installation

To get started, install the EfficientDynamoDb nuget package.

Initializing DynamoDbContext

All requests to DynamoDB in EfficientDynamoDb are done through DynamoDbContext.

First, add the following usings:

using EfficientDynamoDb;
using EfficientDynamoDb.Configs;

Then you can create a DynamoDbContext like that:

var accessKey = Environment.GetEnvironmentVariable("accessKeyVariable");
var secretKey = Environment.GetEnvironmentVariable("secretKeyVariable");

var credentials = new AwsCredentials(accessKey, secretKey);

var config = new DynamoDbContextConfig(RegionEndpoint.USEast1, credentials);
var context = new DynamoDbContext(config);

As you see, there are two main requirements to create the context: RegionEndpoint and AwsCredentials.

Optionally, you can set the table name prefix, HTTP client factory, and retry strategies:

var config = new DynamoDbContextConfig(RegionEndpoint.USEast1, credentials)
{
TableNamePrefix = "your_prefix",
HttpClientFactory = yourFactory
};
config.RetryStrategies.ThrottlingStrategy = DefaultRetryStrategy.Instance;

For more info about retry strategies and possible options, check the retry strategies guide.

Region

AWS Region selection allows you to access DynamoDb in a specific geographic region. It can be useful for redundancy and to keep your data and applications running close to where you and your users access them.

The simplest way to get RegionEndpoint is to use static property like RegionEndpoint.USEast1. Learn more about ways to create RegionEndpoint in our how-to guide.

Credentials

Natively, EfficientDynamoDb supports direct creation of AwsCredentials instance via constructor.

Important note: Never put your credentials as plain text in your code! Use some secure storage instead.

Example:

var accessKey = Environment.GetEnvironmentVariable("accessKeyVariable");
var secretKey = Environment.GetEnvironmentVariable("secretKeyVariable");

var credentials = new AwsCredentials(accessKey, secretKey);

If you want to use token authentication, you can pass it to the AwsCredentials constructor as well:

var accessKey = Environment.GetEnvironmentVariable("accessKeyVariable");
var secretKey = Environment.GetEnvironmentVariable("secretKeyVariable");
var token = "YourToken";

var credentials = new AwsCredentials(accessKey, secretKey, token);

Additionally, you can use all authentication methods from .NET AWS SDK via our credentials compatibility package.

For more info, refer to our guide to credentials management in EfficientDynamoDb