@btc-embedded/cdk-extensions

中文文档
0.24.7发布于 2026/10/26Apache-2.0TypeScriptCommonJS近 30 天下载 3630

A collection of useful CDK extensions and common logic

原始使用文档
文档目录10 节
  1. Features
  2. Installation
  3. Usage Example
  4. Basic Usage
  5. Using ApplicationStack for Simplified Configuration
  6. Config-Driven Deployments
  7. CLI Commands
  8. catnip — Cloud Toolkit by the CAT Department
  9. Documentation
  10. License

BTC Embedded CDK Extensions

@btc-embedded/cdk-extensions

A collection of reusable AWS CDK (Cloud Development Kit) extensions and constructs for building cloud infrastructure with TypeScript.

Features

  • CDK Constructs: Includes ready-to-use constructs for API Gateway, Application Load Balancer, Cognito, VPC, DocumentDB, and more.
  • ECS Service Extensions: Provides ECS service extensions for advanced container orchestration.
  • Utilities: Common utilities and helpers for stack parameters, value imports, and configuration parsing.
  • Modular Extensions: Easily extend AWS resources with features like logging, OpenTelemetry, EFS, Cloud Map, and custom containers.

Installation

yarn install @btc-embedded/cdk-extensions

Usage Example

Basic Usage

import { ApiGateway } from "@btc-embedded/cdk-extensions";

// Use constructs and extensions in your CDK app

Using ApplicationStack for Simplified Configuration

For application-level stacks that reference a base platform stack, use ApplicationStack to ensure consistent use of the base platform stack name:

import { ApplicationStack } from "@btc-embedded/cdk-extensions";

export class MyAppStack extends ApplicationStack {
  constructor(scope: Construct, id: string) {
    super(scope, id, {
      basePlatformStackName: "my-platform-stack",
      env: {
        account: "123456789012",
        region: "eu-central-1",
      },
    });

    // Constructs and extensions automatically resolve the platform stack name
    // No need to pass basePlatformStackName repeatedly
  }
}

Config-Driven Deployments

Use createApplicationApp for configuration-driven deployments:

import {
  createApplicationApp,
  ApplicationStack,
} from "@btc-embedded/cdk-extensions";
import { z } from "zod";

const configSchema = z.object({
  env: z.object({ account: z.string(), region: z.string() }),
  basePlatformStackName: z.string(),
});

createApplicationApp({
  directory: "./config",
  schema: configSchema,
  createStack: (scope, config) => new MyAppStack(scope, "MyApp", config),
});

CLI Commands

catnip — Cloud Toolkit by the CAT Department

catnip provides operational helpers for CloudFormation, ECS, and Cognito.

Global options (apply to all commands):

  • --region <region> — AWS region (defaults to AWS_DEFAULT_REGION / AWS_REGION)
  • --profile <profile> — AWS named profile

stack-diagnose

Diagnose failed CloudFormation deployments and show ECS failure context.

Usage:

catnip stack-diagnose
catnip stack-diagnose --stack-name my-stack
catnip stack-diagnose --stage prod
catnip stack-diagnose --stack-name my-stack --tail 200 --tasks 10

Options:

  • --stack-name <name> — stack to diagnose (optional; auto-detects last failed stack if omitted)
  • --stage <name> — stage filter for auto-detection (ignored if --stack-name is provided)
  • --tail <n> — Number of log lines to show per container (default: 100)
  • --tasks <n> — Number of recent stopped tasks to inspect (default: 5)

ecs-logs

Stream live logs from running ECS services in a CloudFormation stack.

Usage:

catnip ecs-logs --stack-name my-stack
catnip ecs-logs --stack-name my-stack --follow
catnip ecs-logs --stack-name my-stack --service api --tail 50
catnip ecs-logs --stack-name my-stack --output raw
catnip ecs-logs --stack-name my-stack --output pretty

Options:

  • --stack-name <name> — CloudFormation stack name (required)
  • --tail <n> — Lines of history to show per container (default: 100)
  • -f, --follow — Keep polling for new log events
  • --service <name> — Filter services by name
  • -o, --output <mode> — Output mode: text, raw, or pretty (default: text)

oidc-token

Fetch a Cognito token using CloudFormation exports from a stack.

Usage:

catnip oidc-token --stack-name my-stack
catnip oidc-token --stack-name my-stack --output json

Options:

  • --stack-name <name> — stack that exported Cognito resources (required)
  • --output <token|json> — print token only, or full response JSON (default: token)
    • token output is the access_token

pg-tunnel

Open a secure Session Manager tunnel to Aurora PostgreSQL and launch a local client.

Usage:

catnip pg-tunnel --stack-name my-stack
catnip pg-tunnel --stack-name my-stack --exec "psql"
catnip pg-tunnel --stack-name my-stack --database app
catnip pg-tunnel --stack-name my-stack --no-auto-launch
catnip pg-tunnel --stage prod

Options:

  • --stack-name <name> — stack where the Aurora cluster is deployed (typically the base platform stack; optional when auto-discovery works)
  • --stage <name> — stage filter used during stack auto-discovery
  • --local-port <port> — preferred local port (default: 5432)
  • --database <name> — overrides PGDATABASE for launched client/shell
  • --exec <command> — explicit command to run after tunnel starts
  • --no-auto-launch — keep tunnel attached without launching a client/shell
  • --tunnel-instance-id <id> — fallback EC2 instance ID when stack export is missing

Database selection behavior:

  • if --database is provided, that value is used
  • if omitted, catnip infers database names from deployed ECS service task definitions (POSTGRES_DATABASE)
  • if exactly one database is inferred, it is applied as PGDATABASE
  • if multiple databases are inferred, they are printed with source stack/service and PGDATABASE remains unset

Prerequisite:

  • session-manager-plugin must be installed and available in PATH

Documentation

License

Apache-2.0 © BTC Embedded Systems AG

版本与发布记录

@btc-embedded/cdk-extensions 共发布 134 个版本,首次发布于 2024/12/13;过去 12 个月发布了 78 个版本。

版本发布日期距今
0.24.7latest2026/10/2613 天前
0.24.52026/09/012 个月前
0.24.42026/08/172 个月前
0.24.32026/08/043 个月前
0.24.22026/08/043 个月前
0.24.12026/07/293 个月前

关于 @btc-embedded/cdk-extensions 的常见问题

@btc-embedded/cdk-extensions 是什么?

A collection of useful CDK extensions and common logic

如何安装 @btc-embedded/cdk-extensions?

在项目目录运行 npm install @btc-embedded/cdk-extensions,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.5.1)、aws-cdk-lib(^2.260.0)、cdk-monitoring-constructs(^9.0.0)、@aws-cdk-containers/ecs-service-extensions(>=2.0.1-alpha.535)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 catnip,可以用 npx catnip 直接运行。

@btc-embedded/cdk-extensions 支持 TypeScript 吗?

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

@btc-embedded/cdk-extensions 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@btc-embedded/cdk-extensions 可以商用吗?

@btc-embedded/cdk-extensions 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@btc-embedded/cdk-extensions 的下载量有多少?

根据 npm 官方下载统计,@btc-embedded/cdk-extensions 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,630 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@btc-embedded/cdk-extensions 还在维护吗?

最新版本 0.24.7 发布于 2026/10/26(13 天前);至今共发布 134 个版本,其中过去 12 个月发布了 78 个;首次发布于 2024/12/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。