dynamodb

package
v0.0.0-...-8ab1257 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

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

By caching feature flag data in DynamoDB, LaunchDarkly clients don't need to call out to the LaunchDarkly API every time they're created. This is useful for environments like AWS Lambda where workloads can be sensitive to cold starts.

In contrast to the Redis-backed feature store, the DynamoDB store can be used without requiring access to any VPC resources, i.e. ElastiCache Redis. See https://blog.launchdarkly.com/go-serveless-not-flagless-implementing-feature-flags-in-serverless-environments/ for more background information.

Here's how to use the feature store with the LaunchDarkly client:

store, err := dynamodb.NewDynamoDBFeatureStore("some-table", nil)
if err != nil { ... }

config := ld.DefaultConfig
config.FeatureStore = store
config.UseLdd = true // Enable daemon mode to only read flags from DynamoDB

ldClient, err := ld.MakeCustomClient("some-sdk-key", config, 5*time.Second)
if err != nil { ... }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamoDBFeatureStore

type DynamoDBFeatureStore struct {
	// Client to access DynamoDB
	Client dynamodbiface.DynamoDBAPI

	// Name of the DynamoDB table
	Table string

	// Logger to write all log messages to
	Logger ld.Logger
	// contains filtered or unexported fields
}

DynamoDBFeatureStore provides a DynamoDB-backed feature store for LaunchDarkly.

func NewDynamoDBFeatureStore

func NewDynamoDBFeatureStore(table string, logger ld.Logger) (*DynamoDBFeatureStore, error)

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

This function uses https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#NewSession to configure access to DynamoDB, which means that environment variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION work as expected.

For more control, compose your own DynamoDBFeatureStore with a custom DynamoDB client.

func (*DynamoDBFeatureStore) All

All returns all items currently stored in DynamoDB that are of the given data kind. (It won't return items marked as deleted.)

func (*DynamoDBFeatureStore) Delete

func (store *DynamoDBFeatureStore) Delete(kind ld.VersionedDataKind, key string, version int) error

Delete marks an item as deleted. (It won't actually remove the item from DynamoDB.)

func (*DynamoDBFeatureStore) Get

Get returns a specific item with the given key. It returns nil if the item does not exist or if it's marked as deleted.

func (*DynamoDBFeatureStore) Init

func (store *DynamoDBFeatureStore) Init(allData map[ld.VersionedDataKind]map[string]ld.VersionedData) error

Init initializes the store by writing the given data to DynamoDB. It will delete all existing data from the table.

func (*DynamoDBFeatureStore) Initialized

func (store *DynamoDBFeatureStore) Initialized() bool

Initialized returns true if the store has been initialized.

func (*DynamoDBFeatureStore) Upsert

func (store *DynamoDBFeatureStore) Upsert(kind ld.VersionedDataKind, item ld.VersionedData) error

Upsert either creates a new item of the given data kind if it doesn't already exist, or updates an existing item if the given item has a higher version.

Jump to

Keyboard shortcuts

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