npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-parameter-store-env

v0.0.6

Published

Loads environment variables from AWS Parameter Store

Downloads

6,994

Readme

aws-parameter-store-env

aws-parameter-store-env is a module that loads environment variables from AWS Parameter Store into process.env.

Install

# with npm
npm install aws-sdk aws-parameter-store-env

# with yarn
yarn add aws-sdk aws-parameter-store-env

Usage

Assuming the following parameters are defined in the AWS Parameter Store:

  • app/production/DB_HOST
  • app/production/DB_USER
  • app/production/DB_PASS

The following config can be used to pull those parameters into process.env.

require("aws-parameter-store-env")
  .config({
    path: "app/production/",
    parameters: [
      {
        name: "DB_HOST"
      },
      {
        name: "DB_USER",
        envName: "DB_USERNAME"
      },
      {
        name: "DB_PASS",
        envName: "DB_PASSWORD"
      }
    ],
    region: "us-east-1"
  })
  .then(() => {
    const { DB_HOST, DB_USERNAME, DB_PASSWORD } = process.env;
    // code to run after the environment has been configured
  });

Config

Options

parameters

This value is an array of Parameter objects that define which parameters should be retrieved from the AWS Parameter Store and how those parameters should be named when saved to process.env.

Here is an example Parameter object

{
  name: "app/production/secret",
  envName: "APP_SECRET"
}

The name attribute of the Parameter object is the name of the attribute to be retrieved from the AWS Parameter Store.

The envname attribute of the Parameter object is the name that should be used when applying the parameter value process.env. If this attribute isn't defined the name attribute will be used.

require("aws-parameter-store-env")
  .config({
    parameters: [
      {
        name: "app/production/DB_HOST",
        envName: "DB_HOST"
      },
      {
        name: "app/production/DB_USER",
        envName: "DB_USER"
      },
      {
        name: "app/production/DB_PASS",
        envName: "DB_PASS"
      }
    ],
    region: "us-east-1"
  })
  .then(() => {
    const { DB_HOST, DB_USER, DB_PASS } = process.env;
    // code to run after the environment has been configured
  });

path

The path attribute can be used to reduce redundancy in Parameter names.

require("aws-parameter-store-env")
  .config({
    path: "app/production/"
    parameters: [
      {
        name: "DB_HOST",
      },
      {
        name: "DB_USER",
      },
      {
        name: "DB_PASS",
      }
    ],
    region: "us-east-1"
  })
  .then(() => {
    const { DB_HOST, DB_USER, DB_PASS } = process.env;
    // code to run after the environment has been configured
  });

region

This value is passed to aws-sdk when the SSM service is created. This is the AWS region to pull parameters from.

withDecryption

Default: true

This value is passed passed to aws-sdk. It's then used to decide if secure string values should be decrypted by the SDK. See the AWS documentation for more information.

require("aws-parameter-store-env")
  .config({
    parameters: [
      {
        name: "parameter/store/var/that/you/dont/want/decrypted",
        envName: "ENCRYPTED_VAR"
      }
    ],
    region: "us-east-1",
    withDecryption: false
  })
  .then(() => {
    const { ENCRYPTED_VAR } = process.env;
    // code to run after the environment has been configured
  });

Callback

If you prefer callbacks over promises a callback can be passed as a second parameter to config.

require("aws-parameter-store-env").config(
  {
    path: "app/production/",
    parameters: [
      {
        name: "DB_HOST"
      },
      {
        name: "DB_USER",
        envName: "DB_USERNAME"
      },
      {
        name: "DB_PASS",
        envName: "DB_PASSWORD"
      }
    ],
    region: "us-east-1"
  },
  () => {
    const { DB_HOST, DB_USERNAME, DB_PASSWORD } = process.env;
    // code to run after the environment has been configured
  }
);