79443421

Date: 2025-02-16 15:32:30
Score: 0.5
Natty:
Report link

Is there a specific reason why you are loading configs using an async function?

You might want to consider using environment variables with the resolve keyword, which allows you to inject secrets at runtime without fetching them manually in your application code.

AWS Secrets Manager supports referencing secrets directly in environment variables. You can define them in your serverless.yml like this:

provider:
  stage: ${opt:stage, "your-stage"}
  environment:
    DB_NAME: '{{resolve:secretsmanager:youraccount-${self:provider.stage}:SecretString:dbName}}'
    DB_PASS: '{{resolve:secretsmanager:youraccount-${self:provider.stage}:SecretString:dbPass}}'

If you are not using multiple stages, you can simplify this further by removing the stage reference from the secret path.

With this approach, your NestJS app can simply access these values through process.env without any additional async calls, something like this:

const DB_NAME = process.env.DB_NAME
const DB_PASS = process.env.DB_PASS
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Is there a
  • Low reputation (0.5):
Posted by: Peca021