【问题标题】:How to get and use the Secret Manager values before the modules load in the NodeJS?如何在 NodeJS 中加载模块之前获取和使用 Secret Manager 值?
【发布时间】:2019-12-02 19:19:55
【问题描述】:

我有一个 Node JS 项目,它有处理程序、服务和模型。 作为应用程序的一部分,我们曾经从配置 js 文件中读取环境变量,该文件因每个环境而异。 最近我们尝试将这些配置 js 信息移动到 AWS Secret Manager。现在我们能够从公共模块中的 Secret Manager 中获取所有值。 我们有近 15 个模块,每个模块都有自己的环境变量。 (每个模块都是一个微服务)。 如何实现以获取每个环境的所有秘密值(从公共模块启动时的负载类型。 现在我在我的处理程序中使用以下方法。

已使用以下方法将值从公共模块获取到工作模块。(处理程序)

const utils = require('common-module');
((err, response) => {
    utils.getAllEnvValues({ secretValue: 'SEARCH-SECRET' }, (err, result) => {
        if (err) {
            console.log(err)
        }
        console.log('Getting the value from AWS Secrets!!!!');
        console.log('Limit Size:', process.env.SEARCH_LIMIT);
    });
})();

但有时不需要加载所有模块。即使是那些模块也应该得到它们的环境值? 如何获得这些?什么样的实施将在这里有所帮助?

【问题讨论】:

    标签: node.js aws-secrets-manager


    【解决方案1】:

    查看此包:https://github.com/jwerre/secrets

    它会像这样在特定命名空间(或不)内同步加载你的所有秘密:

    const config = require('@jwerre/secrets').configSync({
        region: 'us-east-1',
        env: 'production',
        namespace: 'SEARCH-SECRET',
    });
    

    【讨论】:

      猜你喜欢
      • 2022-01-27
      • 2023-01-30
      • 2019-04-13
      • 2019-11-14
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多