1.0.1 • Published 6 months ago

@brekjs/loader-aws-secrets-manager v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Brek AWS Secrets Manager Loader

build status SemVer Conventional Commits AutoRel

This is a loader for brek that loads secrets from AWS Secrets Manager. It is a simple and easy-to-use loader that allows you to load secrets from AWS Secrets Manager into your configuration.

Installation

  1. Install the package and brek using npm/yarn:

    npm install @brekjs/loader-aws-secrets-manager brek
  2. Install the AWS SDK v3:

    npm install @aws-sdk/client-secrets-manager
  3. Configure your AWS credentials:

    You can do this by setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, or by using the AWS CLI to configure your credentials. You can also use OpenID Connect or AWS SSO to authenticate.

  4. Set IAM Policy:

    Make sure that the IAM role you are using for your server has the necessary permissions to access the secrets in AWS Secrets Manager. You can do this by attaching the following policy to role (as an example):

    Version: '2012-10-17'
    Statement:
        - Effect: Allow
          Action:
            - secretsmanager:GetSecretValue
            - secretsmanager:DescribeSecret
          Resource: "*"

    Read more about IAM policies and AWS Secrets Manager permissions.

Usage

To use the loader, you need to add it to your brek configuration. You can do this by adding the following code to your brek.loaders.js configuration file:

brek.loaders.js

const {awsSecret} = require('@brekjs/loader-aws-secrets-manager');

module.exports = {
    awsSecret,
};

Then, you can use the loader in your configuration files. For example, if you have a configuration file called /config/prod.json, you can use the loader like this:

config/prod.json

{
  "foo": {
    "[awsSecret]": {
      "key": "foo",
      "region": "us-east-1"
    }
  }
} 

Note: Region is optional but recommended.

The loader will automatically load the secret from AWS Secrets Manager and replace the [awsSecret] placeholder with the value of the secret.

blah.ts

import {getConfig} from "brek";

const {foo} = getConfig();
console.log(foo); // MySuperSecretValue

🔗 Learn more about how to use Loaders with brek

Contributing

  • ⭐ Star this repo if you like it!
  • 🐛 Open an issue for bugs or suggestions.
  • 🤝 Submit a PR to main — all tests must pass.