Skip to content

Amazon DynamoDB grain persistence

In this article, you learn how to install and configure Amazon DynamoDB grain persistence.

Install the Microsoft.Orleans.Persistence.DynamoDB package from NuGet.

Configure the DynamoDB grain persistence provider using the DynamoDBSiloBuilderExtensions.AddDynamoDBGrainStorage extension method.

siloBuilder.AddDynamoDBGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.AccessKey = "<DynamoDB access key>";
options.SecretKey = "<DynamoDB secret key>";
options.Service = "<DynamoDB region name>"; // Such as "us-west-2"
});
);

If your authentication method requires a token or a non-default profile name, you can define those properties. First, view your credentials file using the following command:

Terminal window
cat ~/.aws/credentials

As an example, the following configuration shows how to configure the DynamoDB grain persistence provider to use the default profile from the ~/.aws/credentials file:

Terminal window
[YOUR_PROFILE_NAME]
aws_access_key_id = ***
aws_secret_access_key = ***
aws_security_token = ***
aws_session_expiration = ***
aws_session_token = ***

This configuration allows for both types of authentication credentials:

  • access key & secret key
  • access key & secret key & token

Applies to: Orleans 7.0, Orleans 8.0, Orleans 9.0, Orleans 10.0

siloBuilder.AddDynamoDBGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.AccessKey = "***";
options.SecretKey = "***";
options.Service = "***";
options.ProfileName = "***";
options.Token = "***";
});

For more information on AWS credentials and named profiles, see AWS Credentials and Named profiles in the AWS documentation.

Grain storage serialization is configured using the IGrainStorageSerializer interface. By default, grain state serializes using Newtonsoft.Json. You can customize the serializer by setting the GrainStorageSerializer property. For more information on configuring grain storage serializers, see Grain storage serializers.

Applies to: Orleans 3.x

siloBuilder.AddDynamoDBGrainStorage(
name: "profileStore",
configureOptions: options =>
{
options.UseJson = true;
options.AccessKey = "***";
options.SecretKey = "***";
options.Service = "***";
options.ProfileName = "***";
options.Token = "***";
});

For more information on AWS credentials and named profiles, see AWS Credentials and Named profiles in the AWS documentation.