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

@byu-oit/env-ssm

v3.4.0

Published

Gets params from your environment first, then from the ssm parameter store.

Downloads

953

Readme

Commitizen friendly  npm

env-ssm

Load environment from SSM Parameter Store.

Install

This package has a peer dependency to env-var and @aws-sdk/client-ssm. To install, use the following command:

npm install @byu-oit/env-ssm @aws-sdk/client-ssm env-var

If specifying a tfvars file, please install @byu-oit/dottfvars: npm install @byu-oit/dottfvars

If specifying a dotenv file, please install dotenv: npm install dotenv

For convenience installing them all: npm install @byu-oit/env @aws-sdk/client-ssm env-var @byu-oit/dottfvars dotenv

Options

| Option | Type | Description | Default | |:--------------|:--------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------| | ssm | SSMClient | An AWS SSM client instance. The default SSM client can be configured with environment variables or a custom instance may be provided. | SSMClient | | paths | PathSsmLike OR PathSsmLike[] | The SSM parameter store path to use. All parameters that fall under this path will be returned as properties in the environment variables object. Parameters with multiple nested children will be returned as stringified JSON. | [] | | pathDelimiter | string | Specify a path delimiter. | / | | processEnv | boolean | If true, it will add process.env variables to the container. | true | | tfvars | string | Adds local tfvars variables to the environment. Must be the exact path to the tfvars file relative to the project or package root. | false | | dotenv | boolean OR string | Adds local .env variables to the environment. Can be false, which disables .env support. May also be the exact path to the .env file relative to the project or package root. | process.cwd() + '/.env' |

ProTip: Use environment variables to the following options:

  • ENV_SSM_PATHS
  • ENV_SSM_PATH_DELIMITER
  • ENV_SSM_PROCESS_ENV
  • ENV_SSM_TFVARS
  • ENV_SSM_DOTENV

NOTE: All the options are cast from string to the type listed in the table above. When using ENV_SSM_PATHS, a comma-delimited list of paths (e.g. /app/dev,/app/prd) or JSON object or array of PathSsmLike may be supplied.

Usage

Variables load (and are overwritten if duplicates are found) in the following order:

  1. Load SSM
  2. Load .env file
  3. Load .tfvars file
  4. Load process.env

Single Path

SSM Path: /my/app SSM Parameters:

  • /my/app/db/user => admin
  • /my/app/db/pass => ch@ng3m3
  • /my/app/host => example.com
import EnvSsm from 'env-ssm'

/**
 * @returns {db: {user: 'admin', pass: 'ch@ng3m3'}, host: 'example.com'}
 */
async function getParams () {
  const env = await EnvSsm(path)
  const db = env.get('db').required().asJsonObject()
  const host = env.get('api').required().asString()
  return { db, host }
}

Multiple Paths & Delimiters

SSM Paths:

  • /my/app
  • my.app

SSM Parameters:

  • /my/app/db/user => admin
  • /my/app/db/pass => ch@ng3m3
  • my.app.host => example.com
import EnvSsm from 'env-ssm'

/**
 * @returns {db: {user: 'admin', pass: 'ch@ng3m3'}, host: 'example.com'}
 */
async function getParams () {
  const env = await EnvSsm([
    '/my/app',

    // If no delimiter is specified, the path is treated as a single property name
    { path: 'my.app', delimiter: '.' }
  ])
  const db = env.get('db').required().asJsonObject()
  const host = env.get('api').required().asString()
  return { db, host }
}

For Local Development

For the given tfvars, .env, and ssm path:

SSM Path: /my/app SSM Parameters:

  • /my/app/db/user => admin
# local.tfvars file located in current working directory
db = {
  user = 'user'
  pass = 'ch@ng3m3'
}
host = 'JohnDoe.com'
# .env file located in current working directory
host='example.com'
/**
 * @returns {db: {user: 'user', pass: 'ch@ng3m3'}, host: 'JohnDoe.com'}
 */
async function getParams () {
  const env = await EnvSsm({
    // Allows multiple paths
    paths: [path],

    // Specify file name relative to process.cwd()
    tfvars: 'local.tfvars',

    // By default, checks process.cwd() + '/.env' or else specify a file name relative to process.cwd()
    // dotenv: .env
  })
  const db = env.get('db').required().asJsonObject()
  const host = env.get('api').required().asString()
  return { db, host }
}