lddynamodb

package
v4.0.0-...-0933bec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package lddynamodb provides a DynamoDB-backed feature store for the LaunchDarkly Go SDK.

For more details about how and why you can use a persistent feature store, see: https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store

To use the DynamoDB feature store with the LaunchDarkly client:

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name")
if err != nil { ... }

config := ld.DefaultConfig
config.FeatureStore = store
client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)

Note that the specified table must already exist in DynamoDB. It must have a partition key of "namespace", and a sort key of "key".

By default, the feature 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 SessionOptions function, or use an already-configured client via the DynamoClient function.

If you are using the same DynamoDB table as a feature store for multiple LaunchDarkly environments, use the Prefix option and choose a different prefix string for each, so they will not interfere with each other's data.

Index

Constants

View Source
const (
	// DefaultCacheTTL is the amount of time that recently read or updated items will be cached
	// in memory, unless you specify otherwise with the CacheTTL option.
	DefaultCacheTTL = 15 * time.Second
)

Variables

This section is empty.

Functions

func NewDynamoDBFeatureStore

func NewDynamoDBFeatureStore(table string, options ...FeatureStoreOption) (ld.FeatureStore, error)

NewDynamoDBFeatureStore creates a new DynamoDB feature store to be used by the LaunchDarkly client.

By default, this function uses https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#NewSession to configure access to DynamoDB, so the configuration will use your local AWS credentials as well as AWS environment variables. You can also override the default configuration with the SessionOptions option, or use an already-configured DynamoDB client instance with the DynamoClient option.

For other options that can be customized, see CacheTTL and Logger.

Types

type FeatureStoreOption

type FeatureStoreOption interface {
	// contains filtered or unexported methods
}

FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewDynamoDBFeatureStore. These include SessionOptions, CacheTTL, DynamoClient, and Logger.

func CacheTTL

func CacheTTL(ttl time.Duration) FeatureStoreOption

CacheTTL creates an option for NewDynamoDBFeatureStore to set the amount of time that recently read or updated items should remain in an in-memory cache. This reduces the amount of database access if the same feature flags are being evaluated repeatedly. If it is zero, there will be no in-memory caching. The default value is DefaultCacheTTL.

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name", lddynamodb.CacheTTL(30*time.Second))

func ClientConfig

func ClientConfig(config *aws.Config) FeatureStoreOption

ClientConfig creates an option for NewDynamoDBFeatureStore to add an AWS configuration object for the DynamoDB client. This allows you to customize settings such as the retry behavior.

func DynamoClient

func DynamoClient(client dynamodbiface.DynamoDBAPI) FeatureStoreOption

DynamoClient creates an option for NewDynamoDBFeatureStore to specify an existing DynamoDB client instance. Use this if you want to customize the client used by the feature store in ways that are not supported by other NewDynamoDBFeatureStore options. If you specify this option, then any configurations specified with SessionOptions or ClientConfig will be ignored.

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name", lddynamodb.DynamoClient(myDBClient))

func Logger

func Logger(logger ld.Logger) FeatureStoreOption

Logger creates an option for NewDynamoDBFeatureStore, to specify where to send log output. If not specified, a log.Logger is used.

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name", lddynamodb.Logger(myLogger))

func Prefix

func Prefix(prefix string) FeatureStoreOption

Prefix creates an option for NewDynamoDBFeatureStore to specify a string that should be prepended to all partition keys used by the feature store. A colon will be added to this automatically. If this is unspecified, no prefix will be used.

store, err := lddynamodb.NewDynamoDBFeatureStore(lddynamodb.Prefix("ld-data"))

func SessionOptions

func SessionOptions(options session.Options) FeatureStoreOption

SessionOptions creates an option for NewDynamoDBFeatureStore, to specify an AWS Session.Options object to use when creating the DynamoDB session. This can be used to set properties such as the region programmatically, rather than relying on the defaults from the environment.

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name", lddynamodb.SessionOptions(myOptions))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL