Automate LaunchDarkly flag updates from AWS events.
This is a proof of concept. The idea is that when certain services are not available we may want to turn off related features automatically.
An AWS Lambda function is configured to listen to AWS CloudWatch events, and toggle flags accordingly. At this stage a single flag is toggled based on EC2 instance state.
API calls to LaunchDarkly are managed using https://github.com/wyvern8/launchdarkly-nodeutils
You will need to have configured https://serverless.com/ framework and aws sdk.
- clone this repo
- run
npm install
- configure a
.env
file based on.envExample
- run
npm run sls-deploy
- stop and start the instance you configured in
.env
and confirm the LaunchDarkly flag toggles on and off.
You can tail the Lambda logs while stopping and starting using npm run sls-logs
As this is an initial prototype, it currently supports one flag toggled off when a single instance is not in 'running' state, and back on when it is running. This could be expanded to cater for a configurable list of events and associated flags (TODO). Event types: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
Note that a couple of workarounds for loading swagger.yaml in Lambda are currently in place - this will be tidied up.