Schedule feature flag toggling using AWS Lambda & CloudWatch.
Overview: Run CLI command to create a CloudWatch cron-scheduled Event with a payload containing feature ID, toggle state (on/off), and environment name. When the scheduled Event is triggered, it will invoke a Lambda function and pass along the payload which will be used to toggle feature state via the Optimizely REST API.
$ python run.py schedule -feature 8930855000 -toggle on -date "3-1-2019 17:45:00" -env production
$ python run.py schedule -feature 8930855000 -toggle off -date "3-20-2019 17:45:00" -env production
$ python run.py list
will print out scheduled jobs and their 'job name'
Scheduled Jobs:
================
Feature ID Toggle State Date Env Job Name
8930855000 DISABLE 03-20-2019 17:45:00(UTC) production OPTLY_FLAG_8930855000_off_production
8930855000 ENABLE 03-1-2019 17:45:00(UTC) production OPTLY_FLAG_8930855000_on_production
$ python run.py delete -job OPTLY_FLAG_8930855000_on_production
$ python run.py flag -toggle on -feature 8930855000 -env stage
Environments:
>= Python 3.6
- The AWS connectivity is handled by named profiles
- The named profile used by the CLI must be set as an environment variable
OPTLY_LAMBDA_AWS_PROFILE
- The Lambda function ARN must be set as an environment variable
OPTLY_LAMBDA_FNC_ARN
- The Lambda function ID must be set as an environment variable
OPTLY_LAMBDA_FNC_ID
The files contents of lambda_function/lambda_function.py
can be placed directly within a Lambda function
- The Optimizely "personal token" must be set as the
v2_token
environment variable in the Lambda function configuration screen within AWS
Nothing needs to be done on the CloudWatch dashboard, but it helps troubleshoot by being able to refresh your list of scheduled jobs via the interface
- Support for specifying rollout %
- Support for relative timezones (requires UTC time currently)