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

@phhu/aws-secrets-to-env

v0.0.20

Published

Node.js CLI script which writes .env files or export commands to stdout based on values held in AWS Parameter Store and/or AWS Secrets Manager

Downloads

25

Readme

This node.js script writes .env files or export commands to stdout based on values held in Amazon Web Services (AWS) Parameter Store and/or AWS Secrets Manager. Node applications can then be run using environment variables set by it, perhaps using package "dotenv" to retrieve from the .env file.

  • Specify --ssmpath and/or --secretid to retrieve from AWS Parameter Store and/or AWS Secrets Manager respectively.
  • For the Parameter Store, parameters are returned by path (e.g. parameters with names starting with an arbitrary path such as "/myapp/prodconfig")
  • For authentication, you can specify --accessKeyId=[awsAccessKeyId] and --secretAccessKey=[awsSecretAccessKey]; or use an AWS profile with --profile=someprofile; otherwise default AWS auth is used.

SAMPLE USAGE:

npm install -g "@phhu/aws-secrets-to-env"
# with global npm install, writing to .env file
aws-secrets-to-env \
--ssmpath=/myapp/prodconfig \
--secretid=/myapp/prodconfig \
--region=eu-central-1 \
>.env && node myapp.js

# with global npm install, setting env. vars using export command
eval $(aws-secrets-to-env \
--secretid=/myapp/prodconfig \
--region=$AWS_DEFAULT_REGION \
--accessKeyId=someAwsAccessKeyId \
--secretAccessKey=$SOME_AWS_ACCESS_KEY_ENV_VAR \
--useexport \
) && node myapp.js

# using local npm install, writing to .env file
node ./node_modules/@phhu/aws-secrets-to-env/aws-secrets-to-env.js \
--secretid=/myapp/prodconfig \
--region=eu-central-1 \
--profile=someAwsProfile \
>.env && node myapp.js

# using npx, writing to .env file
npx "@phhu/aws-secrets-to-env" \
--ssmpath=/myapp/prodconfig \
--region=eu-central-1 \
--profile=someAwsProfile \
>.env && node myapp.js

SAMPLE OUTPUT

As written to .env in the first example above:

VAL1fromParamStore="Value of /myapp/prodconfig/VAL1fromParamStore"
VAL2fromParamStore="encrypted value from parameter store"
VAL1_FromSecretManager="this is stored in /myapp/prodconfig"
VAL2_FromSecretManager="this is also stored in /myapp/prodconfig"
someNumber=1
someArray="[1,2,3]"

With --useexport, as in second example, using eval above:

export VAL_FromSecretManager="this is stored in /myapp/prodconfig"
export someFloat=1.23
export someObj="{\"thing\":1,\"thing2\":2}"

SCRIPT OPTIONS

  • --ssmpath : AWS Param Store Path to retrieve
  • --secretid : AWS Secrets Manager secret ID to retrieve. (This should return JSON key/value pairs)
  • --debug : write debugging info to stderr
  • --help : display this message
  • --useexport : include an "export" command at the start of each line
  • --profile : aws profile to use (from ~/.aws; e.g --profile=default). Alternatively you can set env variable AWS_PROFILE (e.g. export AWS_PROFILE=test && node aws-secrets-to-env.js)

AWS OPTIONS

All other options will be passed through to the AWS request. Useful options include:

  • --region : AWS region. Needs to be specified. e.g. --region=$AWS_DEFAULT_REGION, --region=us-east-1
  • --endpoint : specify an endpoint url (e.g. --endpoint="http://localstack:4566")
  • --accessKeyId
  • --secretAccessKey

(see "options hash" under https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SSM.html and https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SecretsManager.html for more details).