This guide explains the get-dotenv secrets plugin exported by this package:
secretsPlugin() → mounts under aws and provides:
aws secrets pullaws secrets pushaws secrets deleteIf you want the programmatic API instead, see the AwsSecretsManagerTools guide.
npm i @karmaniverous/aws-secrets-manager-tools
You can either:
aws-secrets-manager-tools), orsecretsPlugin() inside your own get-dotenv host.The shipped CLI is a get-dotenv CLI host composed with aws + secrets:
aws-secrets-manager-tools --env dev aws secrets pull --secret-name '$STACK_NAME'
aws-secrets-manager-tools --env dev aws secrets push --secret-name '$STACK_NAME'
aws-secrets-manager-tools --env dev aws secrets delete --secret-name '$STACK_NAME'
Notes:
--env is a get-dotenv root option and must appear before aws ....--secret-name at action time against { ...process.env, ...ctx.dotenv } (ctx.dotenv wins).Mount the plugin under aws:
import { createCli } from '@karmaniverous/get-dotenv/cli';
import { awsPlugin } from '@karmaniverous/get-dotenv/plugins';
import { secretsPlugin } from '@karmaniverous/aws-secrets-manager-tools';
await createCli({
alias: 'toolbox',
compose: (program) => program.use(awsPlugin().use(secretsPlugin())),
})();
Region sourcing:
ctx.plugins.aws.region) when available.aws plugin may export them into process.env depending on its configuration).All plugin commands treat the secret value as an “env-map” JSON object:
{ "KEY": "value", "OPTIONAL": null }
string or null.null is decoded as undefined when reading.aws secrets pullPull reads an env-map secret and applies it as a partial update to a single dotenv file chosen by --to.
--to <scope:privacy>--to selects one target dotenv file:
--to env:private (default) → .env.<env>.<privateToken> (example: .env.dev.local)--to env:public → .env.<env>--to global:private → .env.<privateToken>--to global:public → .envWhen --to env:* is selected, --env (or defaultEnv) must be resolved (the command errors if it cannot determine an environment).
--template-extensionIf the target dotenv file does not exist, but a sibling template does (for example, .env.local.template), the plugin bootstraps the target from the template and then edits it in place. This preserves comments and formatting.
You can configure the template extension via --template-extension or config.
--include / --excludepull supports optional key filtering before editing the dotenv file:
--include <keys...>: write only those keys from the pulled secret--exclude <keys...>: omit those keys from the pulled secret--include and --exclude are mutually exclusive.
aws secrets pushPush selects a subset of loaded keys from ctx.dotenv and writes them to AWS Secrets Manager (create-or-update).
--from <selector> (repeatable)Selection is based on get-dotenv provenance (ctx.dotenvProvenance) using only the effective provenance entry (the last entry for each key).
Key points:
ctx.dotenv (not process.env).undefined, andop: 'unset'.The --from option is repeatable. When omitted, the default is:
--from file:env:privateSupported selector grammar:
file:<scope>:<privacy>
<scope> is global|env|*<privacy> is public|private|*config:<configScope>:<scope>:<privacy>
<configScope> is packaged|project|*<scope> is global|env|*<privacy> is public|private|*dynamic:<dynamicSource>
<dynamicSource> is config|programmatic|dynamicPath|*varsExamples:
# Push only keys whose effective provenance is a public global dotenv file
aws-secrets-manager-tools aws secrets push -s my-secret --from file:global:public
# Allow both file and config layers (effective entry only)
aws-secrets-manager-tools aws secrets push -s my-secret --from file:*:* --from config:*:*:*
--include / --excludeAfter provenance selection, push supports a final narrowing step:
--include <keys...> keeps only those keys--exclude <keys...> removes those keysRules:
--include and --exclude are mutually exclusive.After selection and filtering, the plugin enforces the AWS Secrets Manager SecretString size limit (65,536 bytes, UTF-8):
--from / --include / --exclude.aws secrets deleteDelete removes a secret:
--force to delete without recovery (dangerous).--recovery-window-days <number> to set an explicit recovery window.Safety rules:
--force conflicts with --recovery-window-days.You can set safe defaults in your get-dotenv config under plugins['aws/secrets']:
{
"plugins": {
"aws/secrets": {
"secretName": "$STACK_NAME",
"templateExtension": "template",
"push": {
"from": ["file:env:private"],
},
"pull": {
"to": "env:private",
},
},
},
}
Notes:
push.include|push.exclude and pull.include|pull.exclude, the plugin enforces mutual exclusion at runtime.