@beesolve/aws-env-resolver

中文文档
0.6.2发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 2196

Resolve local development environment from CloudFormation and Secrets Manager, cache it, and inject it into a spawned command

此软件包已被标记为弃用

Renamed to @beesolve/aws-env-loader

原始使用文档
文档目录7 节
  1. Install
  2. CLI
  3. Library ( @beesolve/aws-env-resolver )
  4. CDK ( @beesolve/aws-env-resolver/cdk )
  5. Config
  6. Caching
  7. IAM permissions

@beesolve/aws-env-resolver

Resolve local development environment from CloudFormation and Secrets Manager, cache it, and inject it into a spawned command.

[!WARNING] Pre-1.0 - unstable API. This package is 0.x and under active development. Breaking changes can land in any 0.x release without a major version bump. Pin an exact version and review the changelog before upgrading. Once the API stabilizes and the package reaches 1.0.0, it follows semantic versioning and this notice is removed.

macOS-only secure cache. Secrets are cached in the macOS login keychain. On other platforms secrets are fetched on every run and never written to disk. The CLI requires Bun.

Install

bun add -d @beesolve/aws-env-resolver
npm install --save-dev @beesolve/aws-env-resolver

CLI

aws-env-resolver [--stage <stage>] [options] -- <command...>

Put flags before --. Bun drops a leading --, so with no flags the first non-flag argument starts the command.

FlagDescription
--stage <stage>Optional. Picks aws-env.config.<stage>.* first, passed to a factory, keys caches.
--target <name>Target to resolve when the config defines several. Optional with exactly one target.
--config <path>Config module or JSON (default: aws-env.config.{ts,js,mjs,json} in the cwd).
--profile <name>AWS profile; overrides the config.
--refreshBypass caches and re-fetch from AWS.
--purgeDelete cached values for this stage (runs <command> only if given).
--trustedStore the keychain item so reads are silent (no prompt). See below.
--helpShow help.

The trust list of a keychain item is set when the item is written. With --trusted the resolver writes the item on every run, so an item first stored without the flag is upgraded: that run prompts once and later runs are silent. To switch to trusted mode without running anything, pass --trusted with no command:

aws-env-resolver --stage stg --trusted

Exit codes: 0 success, 1 runtime error, 2 invalid arguments. When a command runs, its exit code is returned.

Library (@beesolve/aws-env-resolver)

ExportDescription
resolveEnv(options: ResolveEnvOptions) => Promise<Record<string, string>>. Does not mutate process.env.
purgeCache({ projectKey, stage?, target?, config }) => Promise<void>. Deletes the cache file and the keychain item.
ResolveEnvOptionsconfig, resources, secrets?, projectKey, stage?, target?, refresh?, cacheTtlMs?, trusted?.
ResolverConfigprofile?, region, stackName (one name or a list), secretId?, accountId?, staticEnv.
ResourceMappingenvVar, logicalIdPrefix, resourceType?, stackName?, transform?.
TemplateMappingenvVar, parts: literal strings and resource references (logicalIdPrefix, ...), concatenated.
SecretMappingenvVar, jsonKey? (defaults to envVar).
ResourceTransformA function (physicalId, { region, accountId }) => string or a TransformTag.
TransformTag{ kind: "lambdaArn" }, for JSON config.
TransformContext{ region, accountId }.
EmittedConfigJSON config shape produced by the CDK emitter: projectKey and targets (name to EmittedTarget).
EmittedTargetOne target's config, resources, secrets?.
emittedConfigSchemaValibot schema for EmittedConfig.
emittedTargetSchemaValibot schema for EmittedTarget.
defaultTarget"default", the target used when none is named.

CDK (@beesolve/aws-env-resolver/cdk)

Requires the optional peers aws-cdk-lib and constructs.

ExportDescription
envOf(construct) => Record<string, DevEnvValue>. The env of the Lambda(s) under a construct.
secret({ secretId, jsonKey? }) => EnvSecret. A Secrets Manager value; jsonKey defaults to the name.
generateDevEnv(props: DevEnvProps) => EmittedConfig. Turns the composed env into a mapping; no I/O.
persistDevEnv(config, { path }) => void. Writes JSON, creating parent directories.
devEnvgenerateDevEnv then persistDevEnv; optional stage and path (default aws-env.config[.<stage>].json).
defaultConfigPath(stage?) => string. The file name devEnv writes without a path.
DevEnvPropsprojectName, env, profile?.
DevEnvValuestring | EnvResource | EnvSecret.

The dev env is a plain object you compose: spread envOf(...) for each construct whose env the local process needs, then add literals and secret(...). Later keys win, so spread order is precedence and two embedded constructs that set the same name to different resources never conflict; you pick one. envOf throws when Lambdas under one construct disagree on a name. All values must share one region. Ref and Fn::GetAtt Arn are supported; other intrinsics throw. Env vars set from secret.secretValueFromJson(key) (a {{resolve:secretsmanager:...}} dynamic reference) are emitted as secret mappings automatically. The emitter writes a recipe (env var to logical-id prefix), never resolved physical names.

Config

The CLI loads the first of aws-env.config.<stage>.ts, .js, .mjs, .json (with --stage), then aws-env.config.ts, .js, .mjs, .json, in the cwd. A module exports an options object or a (stage) => options factory (sync or async). A JSON file is the CDK-emitted form: { projectKey, targets }. With one target --target is optional; with several it is required. A module factory receives (stage, target). A flat JSON file without targets (the pre-targets shape) loads as the default target. Generated config goes to .json, hand-written config goes to .ts.

When an env var appears in several sources, the later one wins: config.staticEnv, then CloudFormation resources, then secrets.

Caching

  • Non-secret values: os.tmpdir()/aws-env-resolver/<projectKey>-<stage>-<fingerprint>.json, 24 hour TTL by default (cacheTtlMs). The file records a hash of the resource mapping, so values cached for a different mapping (for example after regenerating the config) are a miss and get re-fetched.
  • Secrets: macOS keychain, service aws-env-resolver:<projectKey>:<stage>:<fingerprint>, one item holding all secrets as JSON. The fingerprint hashes region, stackName, and secretId, so the cache and keychain share one identity independent of the working directory. A non-default target also enters the cache file's fingerprint (not the keychain's), so targets sharing a stack keep separate resource caches.
  • Default mode stores items with an empty trust list, so macOS may prompt once on read. --trusted stores them with -T /usr/bin/security for silent reads.
  • Steady state makes zero AWS calls.
  • On non-macOS platforms there is no secure cache and secrets are fetched on every run.

IAM permissions

  • cloudformation:ListStackResources
  • secretsmanager:GetSecretValue
  • sts:GetCallerIdentity, only when an ARN transform runs without config.accountId

See DOCS.md for the how-to guides.

版本与发布记录

@beesolve/aws-env-resolver 共发布 12 个版本,首次发布于 2026/10/28;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.2latest2026/11/062 天前
0.6.12026/11/035 天前
0.6.02026/11/026 天前
0.5.02026/10/318 天前
0.4.22026/10/318 天前
0.4.12026/10/318 天前

关于 @beesolve/aws-env-resolver 的常见问题

@beesolve/aws-env-resolver 是什么?

Resolve local development environment from CloudFormation and Secrets Manager, cache it, and inject it into a spawned command注意:该包已被作者标记为弃用——Renamed to @beesolve/aws-env-loader

如何安装 @beesolve/aws-env-resolver?

在项目目录运行 npm install @beesolve/aws-env-resolver,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 aws-env-resolver,可以用 npx aws-env-resolver 直接运行。

@beesolve/aws-env-resolver 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beesolve/aws-env-resolver 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@beesolve/aws-env-resolver 可以商用吗?

@beesolve/aws-env-resolver 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@beesolve/aws-env-resolver 的下载量有多少?

根据 npm 官方下载统计,@beesolve/aws-env-resolver 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,196 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beesolve/aws-env-resolver 还在维护吗?

最新版本 0.6.2 发布于 2026/11/06(2 天前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/10/28。作者已将其标记为弃用,新项目建议寻找替代方案。