Code Monkey home page Code Monkey logo

aws-lambda-serverless's Introduction

Using LaunchDarkly in AWS Lambdas

The goal of this project is to help you get started using LaunchDarkly feature flags within a serverless application using AWS Lambda. The project includes everything you'll need to get started integrating feature flags into your Lambdas using the Node.js runtime.

The LaunchDarkly SDKs

Adding LaunchDarkly feature flags to any Lambda always begins with installing the appropriate SDK for the Lambda runtime you are using. You can find a full list of server-side SDKs here. For the Node.js runtime, that would mean using NPM.

npm install launchdarkly-node-server-sdk

If you would like to use DynamoDB as a persistent feature store, you'll need to also install those dependencies.

npm install launchdarkly-node-server-sdk-dynamodb

This works well for a single Lambda, but if you are using feature flags across a number of Lambdas, the easiest method to maintain the depencies across all of them is using a Lambda Layer. The code provided here will assist you in creating the Layer.

Creating/Updating the Lambda Layer

The necessary dependencies are already included in this project under /cdk/resources/layers. It contains both the Node.js SDK and the DynamoDB extension. In order to ensure that this asset has the latest versions of these SDKs, we've included a script that will download the latest versions and archive them into the proper folder. It is recommended that you run this before deploying any of the assets using the provided CDK scripts. All you need to do is:

cd  create-layer
npm run build

Provided Lambdas

We've provided three example Lambdas to demonstrates the basics of deploying LaunchDarkly within AWS serverless.

  1. getFlagsStarter – This example uses the LaunchDarkly Node.js server SDK to demonstrate how to initialize the SDK client, get a flag value and, as a base use case, establish separate code paths within your Lambda.
  2. getFlagsWithDynamo – This example uses DynamoDB as a persistent feature store for LaunchDarkly feature flags enabling the SDK client to evaluate flag results based upon the data stored in DynamoDB. It is configured to enable daemon mode, which means that it will not call out to LaunchDarkly for these initial values, which can decrease initialization cost and reduce external requests. To disable daemon mode, remove the useLdd flag from the configuration.
  3. syncFlagsToDynamo – This is a simple Lambda designed to force cache flag values into DynamoDB enabling the use of daemon mode. While this solution works, it requires the function to be called (manually or programmatically) to start the initialization. The ideal solution for this problem is to use LauchDarkly's Relay Proxy.

For a complete guide to using LaunchDarkly in AWS serverless, including how to set up the Relay Proxy within your AWS environment and how to ensure that all events are captured by the SDKs within an ephemeral Lambda, visit this guide.

Deploying via the AWS CDK

You'll need to install the CDK. For more details about the AWS CDK and options for installing it, please visit the AWS docs. Once the CDK is installed, follow these commands to bootstrap the deployment and then deploy it to your configured AWS account.

cd cdk
cdk bootstrap
cdk deploy

This will deploy all of the assets discussed above including the Lambda Layer with the LaunchDarkly SDKs and the three example Lambdas, with the Layer as a dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.