Documentation ¶
Overview ¶
Package lddynamodb provides a DynamoDB-backed persistent data store for the LaunchDarkly Go SDK.
For more details about how and why you can use a persistent data store, see: https://docs.launchdarkly.com/sdk/features/storing-data/dynamodb#go
To use the DynamoDB data store with the LaunchDarkly client:
import lddynamodb "github.com/launchdarkly/go-server-sdk-dynamodb/v3" config := ld.Config{ DataStore: ldcomponents.PersistentDataStore(lddynamodb.DataStore("my-table-name")), } client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
By default, the data store uses a basic DynamoDB client configuration that is equivalent to doing this:
dynamoClient := dynamodb.New(session.NewSession())
This default configuration will only work if your AWS credentials and region are available from AWS environment variables and/or configuration files. If you want to set those programmatically or modify any other configuration settings, you can use the methods of the lddynamodb.DataStoreBuilder returned by lddynamodb.DataStore(). For example:
config := ld.Config{ DataStore: ldcomponents.PersistentDataStore( lddynamodb.DataStore("my-table-name").Prefix("key-prefix"), ).CacheSeconds(30), }
Note that CacheSeconds() is not a method of lddynamodb.DataStoreBuilder, but rather a method of ldcomponents.PersistentDataStore(), because the caching behavior is provided by the SDK for all database integrations.
If you are also using DynamoDB for other purposes, the data store can coexist with other data in the same table as long as you use the Prefix option to make each application use different keys. However, it is advisable to configure separate tables in DynamoDB, for better control over permissions and throughput.
Index ¶
- type StoreBuilder
- func (b *StoreBuilder[T]) Build(context subsystems.ClientContext) (T, error)
- func (b *StoreBuilder[T]) ClientConfig(options aws.Config, optFns ...func(*dynamodb.Options)) *StoreBuilder[T]
- func (b *StoreBuilder[T]) ClientOptions(options dynamodb.Options, optFns ...func(*dynamodb.Options)) *StoreBuilder[T]
- func (b *StoreBuilder[T]) DescribeConfiguration() ldvalue.Value
- func (b *StoreBuilder[T]) DynamoClient(client *dynamodb.Client) *StoreBuilder[T]
- func (b *StoreBuilder[T]) Prefix(prefix string) *StoreBuilder[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StoreBuilder ¶
type StoreBuilder[T any] struct { // contains filtered or unexported fields }
StoreBuilder is a builder for configuring the DynamoDB-based persistent data store and/or Big Segment store.
Both DataStore and BigSegmentStore return instances of this type. You can use methods of the builder to specify any ny non-default DynamoDB options you may want, before passing the builder to either github.com/launchdarkly/go-server-sdk/v6/ldcomponents.PersistentDataStore or github.com/launchdarkly/go-server-sdk/v6/ldcomponents.BigSegments as appropriate. The two types of stores are independent of each other; you do not need a Big Segment store if you are not using the Big Segments feature, and you do not need to use the same DynamoDB options for both.
In this example, the main data store uses a DynamoDB table called "table1", and the Big Segment store uses a DynamoDB table called "table2":
config.DataStore = ldcomponents.PersistentDataStore( lddynamodb.DataStore("table1")) config.BigSegments = ldcomponents.BigSegments( lddynamodb.BigSegmentStore("table2"))
Note that the SDK also has its own options related to data storage that are configured at a different level, because they are independent of what database is being used. For instance, the builder returned by github.com/launchdarkly/go-server-sdk/v6/ldcomponents.PersistentDataStore has options for caching:
config.DataStore = ldcomponents.PersistentDataStore( lddynamodb.DataStore("table1"), ).CacheSeconds(15)
func BigSegmentStore ¶
func BigSegmentStore(tableName string) *StoreBuilder[subsystems.BigSegmentStore]
BigSegmentStore returns a configurable builder for a DynamoDB-backed Big Segment store.
The tableName parameter is required, and the table must already exist in DynamoDB.
You can use methods of the builder to specify any non-default Redis options you may want, before passing the builder to github.com/launchdarkly/go-server-sdk/v6/ldcomponents.BigSegments. In this example, the store is configured to use a DynamoDB table called "table1" and the AWS region is forced to be "us-east-1":
config.BigSegments = ldcomponents.BigSegments( lddynamodb.BigSegmentStore("table1").ClientOptions(dynamodb.Options{Region: "us-east-1"}), )
Note that the SDK also has its own options related to Big Segments that are configured at a different level, because they are independent of what database is being used. For instance, the builder returned by github.com/launchdarkly/go-server-sdk/v6/ldcomponents.BigSegments has an option for the status polling interval:
config.BigSegments = ldcomponents.BigSegments( lddynamodb.BigSegmentStore("table1"), ).StatusPollInterval(time.Second * 30)
func DataStore ¶
func DataStore(tableName string) *StoreBuilder[subsystems.PersistentDataStore]
DataStore returns a configurable builder for a DynamoDB-backed data store.
This is for the main data store that holds feature flag data. To configure a data store for Big Segments, use BigSegmentStore instead.
The tableName parameter is required, and the table must already exist in DynamoDB.
You can use methods of the builder to specify any non-default DynamoDB options you may want, before passing the builder to github.com/launchdarkly/go-server-sdk/v6/ldcomponents.PersistentDataStore. In this example, the store is configured to use a DynamoDB table called "table1" and the AWS region is forced to be "us-east-1":
config.DataStore = ldcomponents.PersistentDataStore( lddynamodb.DataStore("table1").ClientOptions(dynamodb.Options{Region: "us-east-1"}), )
Note that the SDK also has its own options related to data storage that are configured at a different level, because they are independent of what database is being used. For instance, the builder returned by github.com/launchdarkly/go-server-sdk/v6/ldcomponents.PersistentDataStore has options for caching:
config.DataStore = ldcomponents.PersistentDataStore( lddynamodb.DataStore("table1"), ).CacheSeconds(15)
func (*StoreBuilder[T]) Build ¶
func (b *StoreBuilder[T]) Build(context subsystems.ClientContext) (T, error)
Build is called internally by the SDK.
func (*StoreBuilder[T]) ClientConfig ¶
func (b *StoreBuilder[T]) ClientConfig(options aws.Config, optFns ...func(*dynamodb.Options)) *StoreBuilder[T]
ClientOptions specifies custom parameters for the dynamodb.NewFromConfig client constructor. This can be used to set properties such as the region programmatically, rather than relying on the defaults from the environment.
func (*StoreBuilder[T]) ClientOptions ¶
func (b *StoreBuilder[T]) ClientOptions(options dynamodb.Options, optFns ...func(*dynamodb.Options)) *StoreBuilder[T]
ClientOptions specifies custom parameters for the dynamodb.New client constructor. This can be used to set properties such as the region programmatically, rather than relying on the defaults from the environment.
func (*StoreBuilder[T]) DescribeConfiguration ¶
func (b *StoreBuilder[T]) DescribeConfiguration() ldvalue.Value
DescribeConfiguration is used internally by the SDK to inspect the configuration.
func (*StoreBuilder[T]) DynamoClient ¶
func (b *StoreBuilder[T]) DynamoClient(client *dynamodb.Client) *StoreBuilder[T]
DynamoClient specifies an existing DynamoDB client instance. Use this if you want to customize the client used by the data store in ways that are not supported by other DataStoreBuilder options. If you specify this option, then any configurations specified with SessionOptions or ClientConfig will be ignored.
func (*StoreBuilder[T]) Prefix ¶
func (b *StoreBuilder[T]) Prefix(prefix string) *StoreBuilder[T]
Prefix specifies a prefix for namespacing the data store's keys.