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

@nekonomokochan/aws-env-creator

v2.0.4

Published

Create an env file from AWS Secrets Manager.

Downloads

768

Readme

aws-env-creator

npm version Build Status Coverage Status

Create an env file from AWS Secrets Manager.

Getting Started

Install npm package

yarn

yarn add @nekonomokochan/aws-env-creator

npm

npm install --save @nekonomokochan/aws-env-creator

Set up AWS credentials

Please set credentials using AWS CLI.

The following is the setting procedure in MacOS.

  1. brew install awscli
  2. aws configure --profile YOUR_PROFILE_NAME
AWS Access Key ID [None]: `YOUR_AWS_ACCESS_KEY_ID`
AWS Secret Access Key [None]: `YOUR_AWS_SECRET_ACCESS_KEY`
Default region name [None]: ap-northeast-1
Default output format [None]: json

profile is optional parameter.

However, in that case please make sure that AWS-SDK can access SecretManager by some means.

For example, there are the following methods.

  • Set credentials for default profile.
  • Give access to SecretManager with IAM policy.

The access key must also have at least the following permissions.

  • secretsmanager:ListSecrets
  • secretsmanager:DescribeSecret
  • secretsmanager:GetSecretValue
  • kms:Decrypt

How To Use

Use With TypeScript

import { createEnvFile, EnvFileType, AwsRegion } from "@nekonomokochan/aws-env-creator";

(async () => {
  const params = {
    type: EnvFileType.dotenv,
    outputDir: "./",
    secretIds: ["dev/app"],
    profile: "nekochans-dev",
    region: AwsRegion.ap_northeast_1
  };

  await createEnvFile(params);
})();

.env is created in your current directory.

Use With JavaScript

(async () => {
  "use strict";

  const awsEnvCreator = require("@nekonomokochan/aws-env-creator");

  const params = {
    type: ".env",
    outputDir: "./",
    secretIds: ["dev/app"],
    profile: "nekochans-dev",
    region: "ap-northeast-1"
  };

  await awsEnvCreator.createEnvFile(params);
})();

.env is created in your current directory.

Set an environment variable with an arbitrary key name

Assume that the following information is registered in your AWS Secret Manager.

{
  "ANOTHER_API_KEY": "another_api_key",
  "ANOTHER_API_SECRET": "another_api_secret"
}

When this code is executed, .envrc is created with the following contents.

(async () => {
    const params = {
      type: EnvFileType.direnv,
      outputDir: "./",
      secretIds: ["dev/app"],
      profile: "nekochans-dev",
      region: AwsRegion.ap_northeast_1,
      keyMapping: {
        ANOTHER_API_KEY: "AWS_API_KEY",
        ANOTHER_API_SECRET: "AWS_API_SECRET"
      }
    };

    await createEnvFile(params);
})();
export AWS_API_KEY=another_api_key
export AWS_API_SECRET=another_api_secret

Define the environment variable to output

When this code is executed, .envrc is created with the following contents.

(async () => {
    const params = {
      type: EnvFileType.direnv,
      outputDir: "./",
      secretIds: ["dev/app"],
      profile: "nekochans-dev",
      region: AwsRegion.ap_northeast_1,
      outputWhitelist: ["ANOTHER_API_KEY"],
    };

    await createEnvFile(params);
})();
export ANOTHER_API_KEY=another_api_key

Optionally set optional parameters

Use With TypeScript

import { createEnvFile, EnvFileType, AwsRegion } from "@nekonomokochan/aws-env-creator";

(async () => {
  const params = {
    type: EnvFileType.dotenv,
    outputDir: "./",
    secretIds: ["dev/app"],
    profile: "nekochans-dev",
    region: AwsRegion.ap_northeast_1,
    addParams: { APP_URL: "http://localhost/3000" }
  };

  await createEnvFile(params);
})();

Use With JavaScript

(async () => {
  "use strict";

  const awsEnvCreator = require("@nekonomokochan/aws-env-creator");

  const params = {
    type: ".env",
    outputDir: "./",
    secretIds: ["dev/app"],
    profile: "nekochans-dev",
    region: "ap-northeast-1",
    addParams: { APP_URL: "http://localhost/3000" }
  };

  await awsEnvCreator.createEnvFile(params);
})();

The following file will be output.

{
  "ANOTHER_API_KEY": "another_api_key",
  "ANOTHER_API_SECRET": "another_api_secret",
  "APP_URL": "http://localhost/3000"
}

create from AWS ParameterStore

You can generate env file from AWS Systems Manager Parameter Store.

For example, suppose that the following ParameterStore is registered.

| key | value | |--------------------------------------|-------------------------| | /dev/test-app/news/sendgrid-api-key | DummySendGridAPIKEY0001 | | /dev/test-app/news/slack-token | DummySlackToken0001 |

You need to specify parameterPath instead of secretIds.

import { createEnvFile, EnvFileType, AwsRegion } from "@nekonomokochan/aws-env-creator";

(async () => {
  const params = {
    type: EnvFileType.dotenv,
    outputDir: "./",
    parameterPath: "/dev/test-app/news",
    profile: "nekochans-dev",
    region: AwsRegion.ap_northeast_1
  };

  await createEnvFile(params);
})();

The contents of the created .env are as follows.

sendgrid-api-key=DummySendGridAPIKEY0001
slack-token=DummySlackToken0001

parameterPath and secretIds can be used together.

A description of the parameter

| parameter | description | value | |-----------------|------------------------------------------------------|-----------------------------------------| | type | The type of file to output | Enum .env .envrc terraform.tfvars | | outputDir | Output path | String | | secretIds | Your AWS Secrets Manager ID | String[] | | parameterPath | Your AWS Parameter Store Path | String | | profile | Your AWS CLI Credentials Name | String | | region | The region where your AWS Secrets Manager is located | String | | outputWhitelist | Output Parameters | String[] | | keyMapping | Key Mapping Object | Object | | addParams | Additional Parameters | Object | | outputFilename | Use this when you want to change the output file name| String |

License

MIT