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