This project contains a CloudFormation template that runs the LaunchDarkly Relay in ECS Fargate.
The template takes two parameters:
-
Stage
: the name of the environment, e.g.dev
,staging
,production
. -
ApiKey
: your LaunchDarkly SDK key
You can deploy this stack using SAM or CDK, or the AWS CLI.
For example, with SAM:
sam deploy --template-file template.yml --stack-name <name of stack> --capabilities CAPABILITY_IAM --parameter-overrides ApiKey=<LaunchDarkly API key> Stage=<name of stage>
With AWS CLI:
aws cloudformation deploy --template-file template.yml --stack-name <name of stack> --capabilities CAPABILITY_IAM --parameter-overrides ApiKey=<LaunchDarkly API key> Stage=<name of stage>
See the example folder for a sample Serverless function that uses node-dynamodb-store to read feature toggles from DynamoDB instead of LaunchDarkly directly.
There are two things you should note from the example project:
-
The LaunchDarkly client is initialized with daemon mode set to
true
(see snippet below). This tells the client to read the feature toggles from DynamoDB instead of LaunchDarkly directly. -
When you call
ldclient.variation
the LaunchDarkly would also make a HTTPs request toevents.launchdarkly.com
to register the user. But this doesn't happen realibly because the Node process is frozen when the invocation finishes. You can callldclient.flush
to flush the events synchronously and wait for it to finish, but this seems to take ~300ms. You also have the option of disabling sending events as well (see snippet below).
const config = { featureStore: store, useLdd: true, sendEvents: false }