Skip to content

This is a feature toggle module for distributed systems based on Node >= 4.x that uses only AWS services.

Notifications You must be signed in to change notification settings

cnnlabs/aws-feature-toggles

Repository files navigation

aws-feature-toggles

This is a module that provides feature toggle capability for distributed systems, using only AWS services (DynamoDB, SNS, SQS).

Features can be enabled based on a name, and a regular expression. For example:

const config = {
    dynamodb: {
        region: 'us-west-2',
        endpoint: 'http://localhost:8000'
    },
    sns: {
        region: 'us-west-2'
    },
    sqs: {
        region: 'us-west-2'
    },
    toggles: {
        system: 'mocha-test'
    }
}
const toggles = require('aws-feature-toggles')(config);

toggles.init(() => {
    toggles.put('testFeature', ['sarah.*'], () => { // notice the array of regex patterns
        const enabled = toggles.check('testFeature', 'sarah@gmail.com');
        // enabled should be true, because the email address matches the regular expression
    });
});

Of course, the target can be anything, not just email addresses. Use ['.*'] to match anything.

Prep

Log into your AWS console and create a new user in IAM. Make sure you save the users credientials. Attach the User Policies for Amazon SQS Full Access and Amazon SNS Full Access.

Create ~/.aws/credentials

Add the access key and secret access key for the IAM user you just created.

[snssqs]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>

Install Packages

npm install

Testing

To start a local copy of dynamoDB for testing, run docker-compose up -d. See docker-compose.yml.

This module requires AWS credentials to run integration tests. Run as follows (using your own AWS profile name):

AWS_PROFILE=<aws profile name> npm test

This module uses the debug module. If you want to see more of what it is doing internally, run with the DEBUG variable like so:

DEBUG=* AWS_PROFILE=<aws profile name> npm test

Inspiration

Borrowed heavily from https://github.com/markcallen/snssqs for SNS and SQS messaging components.

About

This is a feature toggle module for distributed systems based on Node >= 4.x that uses only AWS services.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published