Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic explains how to use the SDK DynamoDB integration as a persistent feature store. Many of our server-side SDKs support DynamoDB. DynamoDB is a particularly useful solution if you are running code in AWS Lambda, because you can access it from Lambda without needing access to any VPC resource.Setup and permissions
In your application code, the only required parameter is the table name, although you can also specify any other options supported by AWS. By default, the DynamoDB driver expects to get your AWS credentials and region from environment variables or local configuration files, as described in the AWS SDK documentation. The table must already exist before your application starts. It must have a partition key called"namespace", and a sort key called "key". The SDK does not create the table automatically because it would not know what values to use for other properties such as permissions and throughput.
DynamoDB imposes a limit of 400KB on the total size of any database item. In this implementation, each feature flag or segment is a single item, so the feature store is not able to persist any flag or segment whose JSON representation is larger than that limit.
For a process to read from the DynamoDB table, it needs the following permissions:
GetItemQuery
PutItemUpdateItemDeleteItemBatchWriteItemConditionCheckItem
How the SDKs store data in Dynamo
DB The DynamoDB integrations for all LaunchDarkly server-side SDKs use the same conventions, so that SDK instances and Relay Proxy instances sharing a single DynamoDB table can interoperate correctly. The storage schema is as follows:- For each data item that the SDK can store, such as a feature flag, there is a single DynamoDB data item, with the following attributes:
namespace: a string value with aKeyTypeofHASHthat denotes the type of data, such asfeaturesandsegments. Or, if you have specified a prefix string, thenamespaceis set toPREFIX:TYPEwherePREFIXis your configured prefix andTYPEis the type of data.key: the unique key of the item, such as the flag key for a feature flag, with aKeyTypeofRANGE.version: a number that the SDK uses to keep track of updates.item: a serialized representation of the data item, in a format that is determined by the SDK.
- An additional item with a
namespaceof$initedorPREFIX:$initedis created when the SDK has stored a full set of feature flag data. This allows a new SDK instance to check whether there is already a valid data set that was stored earlier. - If you have specified a prefix string, the SDK never adds, modifies, or removes any items in the DynamoDB table that do not have a
namespacestarting withPREFIX:, so it is safe to share a DynamoDB table that is also being used for other purposes.
Server-side SDKs
In the following examples, the DynamoDB feature store is set to use a table called"my-table" and a cache TTL of 30 seconds. The DynamoDB feature store does support using a key prefix, as shown in the Redis examples, but it is uncommon for one DynamoDB table to be shared by multiple applications.
This feature is available in the following server-side SDKs:
.NET (server-side)
Expand .NET (server-side) code sample
Expand .NET (server-side) code sample
If using the .NET SDK, you must install the additional package To learn more, read
LaunchDarkly.ServerSdk.DynamoDB.dotnet-server-sdk-dynamodb.Go
Expand Go code sample
Expand Go code sample
The Go integration is in To learn more, read
github.com/launchdarkly/go-server-sdk-dynamodb for version 5.0.0 or higher of the SDK. In versions 4.5.1 and higher, but below 5.0.0, it is in the main SDK distribution as the subpackage lddynamodb.go-server-sdk-dynamodb.Java
Expand Java code sample
Expand Java code sample
If using the Java SDK, you must install the additional package To learn more, read
com.launchdarkly.launchdarkly-java-server-sdk-dynamodb-store. You must also add software.amazon.awssdk.dynamodb if your application does not already use the AWS SDK.java-server-sdk-dynamodb.Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
In version 8.0.0 and higher of the Node.js SDK, you must install the additional package
@launchdarkly/node-server-sdk-dynamodb. If using version 7.x and lower of the Node.js SDK, you must install the additional package launchdarkly-node-server-sdk-dynamodb.In version 5.0 and higher of the Node.js SDK DynamoDB integration, the [AWS SDK for JavaScript v3](https://github.com/aws/aws-sdk-js-v- package is used for DynamoDB operations. As of the 2.0.0 release of that package, the
aws-sdkpackage that it uses is not automatically loaded as a transitive dependency. This saves space when running in AWS Lambda, whereaws-sdkis built in. If you are not running in Lambda, you must separately installaws-sdk.
PHP
Expand PHP code sample
Expand PHP code sample
In version 4.0 and higher of the PHP SDK, you must add the package To learn more, read
launchdarkly/server-sdk-dynamodb to your application’s Composer dependencies to use the DynamoDB integration.In versions 3.x and earlier, the DynamoDB integration is built into the main SDK package, but you must add a package dependency for aws/aws-sdk-php.To use the DynamoDB integration:php-server-sdk-dynamodb.Python
Expand Python code sample
Expand Python code sample
The Python integration is part of the main SDK distribution as of version 6.7.0, but you must also install the package
boto3.Ruby
Expand Ruby code sample
Expand Ruby code sample
The Ruby integration is part of the main SDK distribution as of version 5.1.1, but you must also install the gem
aws-sdk-dynamodb.