Simple implementation of feature toggles that are powered by cloud services.
This module encapsulates all calls to check if a certain feature toggle is enabled. Furthermore, developers can choose a specific cloud service that hosts the feature toggles. Currently the following cloud services are supported:
- AWS
- Azure
- Blob Storage [COMING SOON]
Object to be passed into module instantiation:
aws
- contains all configurations of cloud services under AWSregion
- AWS region (e.g. ap-southeast-1)s3
- use this if you want to use AWS S3 to host your feature togglesbucket
- name of S3 bucket that hosts your feature toggles
dynamoDB
- use this if you want to use AWS DynamoDB to host your feature togglestableName
- name of DynamoDB table that hosts your feature toggles
JSON format that represents the feature toggle:
{
"id": "MY_FEATURE_TOGGLE"
"isEnabled": true
}
Note: For AWS S3
the attribute id
is optional as the name of the file would be the name of the feature toggle i.e. MY_FEATURE_TOGGLE
// instantiate module with options object
const cloudFeatureToggles = require('cloud-feature-toggles')({
aws: {
region: '<REGION>', // e.g. ap-southeast-1
s3: {
bucket: '<FEATURE_TOGGLES_BUCKET>' // e.g. my-feature-toggles
}
}
});
// instantiate module with options object
const cloudFeatureToggles = require('cloud-feature-toggles')({
aws: {
region: '<REGION>', // e.g. ap-southeast-1
dynamoDB: {
tableName: '<FEATURE_TOGGLES_TABLE_NAME>' // e.g. my-feature-toggles
}
}
});
Note: featureToggle
is case sensitive
const main = async() => {
// use isEnabled method to check if MY_FEATURE_TOGGLE is enabled
// note the await keyword
if (await cloudFeatureToggles.isEnabled('MY_FEATURE_TOGGLE')) {
// continue with MY_FEATURE flow
} else {
// continue with normal flow
}
}
main();
- This module primarily uses aws-sdk to connect to S3
- Hence, if this is used in AWS environment (i.e. Lambda or EC2), do make sure that an IAM role with the appropriate policies is attached (i.e. S3 read access)
- If your application is in a non-AWS environment (e.g. Azure), it might be better to utilise Azure Blob Storage to host your feature toggles
- Support for this feature will be COMING SOON