The AWS plugin resolves profile/region and acquires credentials using a safe cascade, writes them to process.env (when enabled), and mirrors the results under ctx.plugins.aws. It also provides an aws subcommand to establish a session and optionally forward to the AWS CLI.
Resolution precedence:
plugins.aws.profile (config override) → ctx.dotenv['AWS_LOCAL_PROFILE'] → ctx.dotenv['AWS_PROFILE'] → undefinedplugins.aws.region (config override) → ctx.dotenv['AWS_REGION'] → best‑effort aws configure get region --profile <profile> → plugins.aws.defaultRegioncli-export by default)AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, they’re used and no CLI calls are made.aws configure export-credentials (JSON, then env‑lines).loginOnDemand is true, run aws sso login --profile <profile> once, then retry export.aws configure get aws_access_key_id/secret_access_key[/aws_session_token].Effects:
setEnv (default true): write AWS_REGION and (if unset) AWS_DEFAULT_REGION, plus credentials variables to process.env.addCtx (default true): mirror { profile?, region?, credentials? } to ctx.plugins.aws.Config keys (JSON/YAML/JS/TS under plugins.aws):
{
"plugins": {
"aws": {
"profile": "dev",
"region": "us-east-1",
"defaultRegion": "us-east-1",
"profileKey": "AWS_LOCAL_PROFILE",
"profileFallbackKey": "AWS_PROFILE",
"regionKey": "AWS_REGION",
"strategy": "cli-export",
"loginOnDemand": true,
"setEnv": true,
"addCtx": true
}
}
}
All fields are optional; defaults favor cli-export with setEnv and addCtx enabled.
awsEstablish a session and optionally forward to the AWS CLI.
getdotenv aws --profile dev --region us-east-1
Writes region/credentials into process.env (when setEnv is not disabled), mirrors into ctx.plugins.aws, and exits 0.
getdotenv aws -- sts get-caller-identity
Forwarded tokens appear after --. The subprocess is invoked with:
{ ...process.env, ...ctx.dotenv }stdio: inherits by default; use --capture or GETDOTENV_STDIO=pipe for deterministic buffering in CI.Session only (respecting config and dotenv overlays):
getdotenv aws --login-on-demand
Assuming plugins.aws in your config sets profile: "dev", the plugin will log in if required and populate both process.env and ctx.plugins.aws.
Forward to AWS:
getdotenv --capture aws -- sts get-caller-identity
Runs the AWS CLI with captured stdout/stderr (buffered and re‑emitted), using a child env composed from the current context.
// Recommended: plugins barrel (shares type identity with cliHost)
import { awsPlugin } from '@karmaniverous/get-dotenv/plugins';
Use it with the plugin‑first host:
import type { Command } from 'commander';
import { GetDotenvCli } from '@karmaniverous/get-dotenv/cliHost';
import { awsPlugin } from '@karmaniverous/get-dotenv/plugins';
const program: Command = new GetDotenvCli('mycli').use(awsPlugin());
await (program as unknown as GetDotenvCli).resolveAndLoad();
await program.parseAsync();
Per‑plugin subpaths remain available when needed:
import { awsPlugin } from '@karmaniverous/get-dotenv/plugins/aws';
setEnv is enabled, the plugin ensures AWS_REGION is set and copies it to AWS_DEFAULT_REGION if that var is unset for broader compatibility.--trace diagnostics and --capture; see the Shell and Plugin‑first host guides for details.