@agiledigital/serverless-parameter-subscriber

serverless plugin to make allow Lambdas to included dynamically updated parameters from the paramter store.

Usage no npm install needed!

<script type="module">
  import agiledigitalServerlessParameterSubscriber from 'https://cdn.skypack.dev/@agiledigital/serverless-parameter-subscriber';
</script>

README

Serverless Parameter Subscriber

CircleCI npm version semantic-release

This is a serverless plugin that enables you to subscribe environment variables in Lambdas to Systems Manager Parameter Store values. This enables you to share configuration values that are used across multiple Lambdas in the Parameter store and access them as environment variables. Need to update the parameter value? Simply update the value once in the Parameter Store and within seconds, all subscribing Lambdas will be using the updated value without the extra overhead of calling out the the parameter store for every request.

Table of Contents

Install

Run npm install in your Serverless project.

$ npm install --save-dev @agiledigital/serverless-parameter-subscriber

Add the plugin to your serverless.yml file

plugins:
  - '@agiledigital/serverless-parameter-subscriber'

Setup

The following is an example serverless.yml file demonstrating this plugin's usage. You can try the example included in the repository.

service: params

provider:
  name: aws
  runtime: nodejs10.x
  region: ap-southeast-2
  stage: ${opt:stage, 'dev'}

functions:
  one:
    handler: handler.one
    # the following `parameters` value is where the magic happens.
    # ENV_VAR_ONE is the name of the environment variable in the function
    # ParamValue will be the name of the parameter in the Parameter Store.
    parameters:
      ENV_VAR_ONE: ParamValue

  two:
    handler: handler.two
    parameters:
      # this parameter will be defined outside of this service.
      ENV_VAR_TWO: ExternalParamValue

resources:
  Resources:
    # We create the parameter that the funtions subscribe to here, but the
    # parameter can be created any way you like including in another service.
    ParamValue:
      Type: AWS::SSM::Parameter
      Properties:
        Description: Dynamic parameter
        Name: ParamValue
        Type: String
        Value: hello, dave

plugins:
  - '@agiledigital/serverless-parameter-subscriber'