This package provides a fromSecretsManager
ConfigProvider constructor function.
You can use it to read secrets from AWS Secrets Manager as a Config
schema.
The config primitive name must match the secret Name or ARN in Secrets Manager.
For example, Config.string("my_secret_name")
or Config.string("arn:aws:secretsmanager:eu-central-1:123456789012:secret:my_secret_name-AbCdEf")
.
npm install --save @effect-aws/secrets-manager @effect-aws/client-secrets-manager
With default service layer:
import { Effect, Config, Console } from "effect";
import { fromSecretsManager } from "@effect-aws/secrets-manager";
const program = Effect.gen(function* () {
const secret: string = yield* Config.string("my_secret_name");
yield* Console.log("Secret from Secrets Manager: ", secret);
});
program.pipe(
Effect.provide(Layer.setConfigProvider(fromSecretsManager())),
Effect.runPromise,
);
With custom service layer:
import { Effect, Config, Console, Layer } from "effect";
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
import {
BaseSecretsManagerServiceLayer,
SecretsManagerClientInstance,
} from "@effect-aws/client-secrets-manager";
import { fromSecretsManager } from "@effect-aws/secrets-manager";
const program = Effect.gen(function* () {
const secret: string = yield* Config.string("my_secret_name");
yield* Console.log("Secret from Secrets Manager: ", secret);
});
const SecretsManagerClientInstanceLayer = Layer.succeed(
SecretsManagerClientInstance,
new SecretsManagerClient({ region: "eu-central-1" }),
);
const serviceLayer = Layer.provide(
BaseSecretsManagerServiceLayer,
SecretsManagerClientInstanceLayer,
);
program.pipe(
Effect.provide(Layer.setConfigProvider(fromSecretsManager({ serviceLayer }))),
Effect.runPromise,
);