@aws-blocks/bb-dashboard

中文文档
0.3.0发布于 2026/11/02Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 6.3万

Auto-generated CloudWatch Dashboard for application observability.

原始使用文档
文档目录18 节
  1. When to Use
  2. When NOT to Use
  3. Installation
  4. Quick Start
  5. Minimal
  6. With metrics + a Tracer (Recommended)
  7. API Reference
  8. new Dashboard(scope, id, options?)
  9. DashboardOptions
  10. MetricConfig
  11. Error Constants
  12. Auto-Generated Widgets
  13. Dashboard Redirect Route
  14. Log Group
  15. Local Development
  16. Scaling & Cost
  17. Namespace Resolution
  18. Default Dimensions

@aws-blocks/bb-dashboard

Auto-generated CloudWatch Dashboard for application observability.

Design & mock parity details: DESIGN.md

When to Use

  • You've deployed your app and want a single URL to view application health
  • You want pre-configured widgets without manually creating CloudWatch dashboards
  • You need a team dashboard for deployment validation and operational awareness

When NOT to Use

  • You need custom visualizations or interactive data exploration → use CloudWatch console

Installation

npm install @aws-blocks/bb-dashboard

Quick Start

Minimal

import { Dashboard } from '@aws-blocks/bb-dashboard';

const dashboard = new Dashboard(scope, 'dashboard');
// After deploy: a CloudWatch Dashboard with a health + logs section for every
// compute in the app.

The dashboard is organized by compute — each compute in the app is a group. Every group shows a health section and a logs section (logs are always captured). A traces section appears when the app contains a Tracer (tracing is presence-gated: any Tracer turns on X-Ray for every compute). You do not pass Logger / Tracer instances to the dashboard. Metrics are app-scoped (a namespace isn't tied to a compute), so they're passed explicitly, one section per namespace.

import { Metrics } from '@aws-blocks/bb-metrics';
import { Tracer } from '@aws-blocks/bb-tracer';

new Tracer(scope, 'tracing');    // → traces section on every compute
const metrics = new Metrics(scope, 'metrics', { namespace: 'MyApp' });

const dashboard = new Dashboard(scope, 'dashboard', {
  title: 'MyApp — Production',
  // Display toggles (default true) applied to every compute section.
  logs: true,
  traces: true,
  // app-wide; pair each Metrics BB with its own metric names (per-namespace).
  // Also accepts an array of sources, one section per namespace.
  metrics: {
    metrics,
    metricConfigs: [
      { name: 'OrdersPlaced' },
      { name: 'Latency', stat: 'p99', period: 300, title: 'P99 Latency' },
      { name: 'CustomMetric', dimensions: { Service: 'API', Stage: 'prod' } },
    ],
  },
});

How the dashboard resolves each section:

  • Health — the compute's health section, always shown.
  • Logs — shown for every compute (logs are always captured); log group is the compute's own handler log group. Suppress with logs: false.
  • Traces — shown for a compute when tracing is enabled on it (the app contains a Tracer). Suppress with traces: false.
  • Metrics — app-wide, from the metrics option: uses each BB's resolved namespace (defaults to its scope fullId) and defaultDimensions (included in widget queries so they target the correct dimensioned stream).
  • Compute coverage — always every compute in the app (one today). No compute selector is exposed yet.

API Reference

new Dashboard(scope, id, options?)

Creates a CloudWatch Dashboard with auto-generated widgets.

Parameters:

NameTypeRequiredDescription
scopeScopeParentYesParent scope (Scope instance or BlocksStack)
idstringYesUnique identifier
optionsDashboardOptionsNoConfiguration

Properties:

NameTypeDescription
urlstring | nullCloudWatch Dashboard console URL (CfnOutput). string on the CDK construct; null in the default/mock type until deployed
dashboardNamestringThe resolved dashboard name

DashboardOptions

Display toggles

Logs and traces are section display toggles, not composition inputs — the dashboard reads each compute's state directly. Logs are always captured (so logs only hides the section); traces exist only when the app has a Tracer (so traces only hides an otherwise-present section).

OptionTypeDefaultDescription
logsbooleantrueShow the logs section for each compute
tracesbooleantrueShow the traces section for each compute (only ever present when the app has a Tracer)

The dashboard always covers every compute in the app. There is no compute selector yet — one arrives with the multi-compute customer surface (it would otherwise leak an internal type before customers can construct a compute).

Metrics composition

OptionTypeDescription
metricsMetricsSource | MetricsSource[]Metrics source(s) — each pairs a Metrics BB with its own metricConfigs; one app-wide section per namespace

Configuration

OptionTypeDefaultDescription
titlestringidDashboard display title
dashboardNamestringscope.fullIdCloudWatch Dashboard name (max 255 characters, auto-truncated)
defaultTimeRangestring'-PT3H'Default time range (ISO 8601 duration)
routePathstring | false'/aws-blocks/dashboard'Route path for the redirect. Set to false to disable

MetricConfig

Configuration for a single pre-registered CloudWatch metric.

FieldTypeDefaultDescription
namestring(required)CloudWatch metric name
stat'Sum' | 'Average' | 'Maximum' | 'Minimum' | 'p99' | 'p95' | 'p50''Sum'Aggregation statistic
periodnumber60Aggregation period in seconds (must be >= 1)
titlestringmetric nameWidget title override
dimensionsRecord<string, string>undefinedMetric dimensions to narrow scope (e.g., { Service: 'API', Stage: 'prod' })

Error Constants

import { DashboardErrors } from '@aws-blocks/bb-dashboard';

DashboardErrors.InvalidMetricConfig // 'InvalidMetricConfigException'
  • InvalidMetricConfig: Thrown when a metric configuration is invalid (e.g., empty name or invalid period).

Note: InvalidMetricConfig is thrown during CDK synthesis while building widgets, not by the mock/runtime Dashboard constructor.

Auto-Generated Widgets

The following widgets are always included:

Grouped per compute, then an app-wide metrics section:

WidgetSourceCondition
Lambda InvocationsAWS/LambdaPer compute, always
Lambda ErrorsAWS/LambdaPer compute, always
Lambda Duration (Avg + p99)AWS/LambdaPer compute, always
Concurrent ExecutionsAWS/LambdaPer compute, always
X-Ray Trace TableX-RayPer compute, when the app has a Tracer (unless traces: false)
Recent Errors (Log Insights)Log groupPer compute, always (unless logs: false)
Log VolumeAWS/LogsPer compute, always (unless logs: false)
Individual Metric Graph (per metric)User namespaceApp-wide, per metrics source + metricConfigs

(Health widgets are Lambda-shaped for the default compute; other compute types report their own health metrics.)

Dashboard Redirect Route

The Dashboard BB registers a GET route (default: /aws-blocks/dashboard) that 302-redirects to the CloudWatch Dashboard console URL. This provides a convenient, discoverable entry point for developers. Set routePath: false to disable.

  • In AWS: Redirects to the full CloudWatch console URL (requires AWS login).
  • In local dev: Returns 503 with a message to deploy first.
// Custom route path
const dashboard = new Dashboard(scope, 'dashboard', {
  routePath: '/ops/dashboard',
});
// GET /ops/dashboard → 302 → https://<region>.console.aws.amazon.com/cloudwatch/...

Log Group

Each compute's log section queries that compute's own handler log group (the framework-owned group the compute provisions). Logs are always captured, so the log widgets appear for every compute unless you set logs: false.

Local Development

In local dev mode, the mock registers the redirect route but returns 503 (since no CloudWatch Dashboard exists locally):

[Dashboard] Dashboard BB: no-op in local mode (CloudWatch Dashboard is a cloud-only resource).
Will create CloudWatch Dashboard 'My App' on deploy. Run 'npx cdk deploy' to view.

📍 Local observability data:
   • Logs: Check your terminal output - Logger BB writes structured JSON to stdout
   • Metrics: Metrics BB writes EMF-formatted JSON to stdout (visible in terminal)
   • Traces: Tracer stores mock traces to .bb-data/ and logs them to stdout

Scaling & Cost

  • Free tier: Up to 3 dashboards with 50 metrics each
  • Beyond free tier: $3/dashboard/month
  • No runtime cost: Dashboards are static read-only views
  • No API calls at request time

Namespace Resolution

The metrics namespace is read from the Metrics BB's namespace property. The Metrics BB resolves this internally from its options (explicit namespace or fallback to scope fullId).

const metrics = new Metrics(scope, 'metrics', { namespace: 'MyApp/Orders' });
const dashboard = new Dashboard(scope, 'dashboard', { metrics });
// Dashboard uses 'MyApp/Orders' as the CloudWatch namespace

Default Dimensions

When a Metrics BB has defaultDimensions configured, the Dashboard automatically includes those dimensions in widget queries. This ensures widgets target the same dimensioned metric stream that the runtime emits to. Per-metric dimensions in MetricConfig are merged on top (per-metric wins on conflict).

const metrics = new Metrics(scope, 'metrics', {
  namespace: 'MyApp/Orders',
  defaultDimensions: { service: 'orders', env: 'prod' },
});

const dashboard = new Dashboard(scope, 'dashboard', {
  metrics: {
    metrics,
    metricConfigs: [
      { name: 'OrdersPlaced' },  // queries with { service: 'orders', env: 'prod' }
      { name: 'Latency', dimensions: { endpoint: '/api' } },  // { service: 'orders', env: 'prod', endpoint: '/api' }
    ],
  },
});

版本与发布记录

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

版本发布日期距今
0.3.0latest2026/11/025 天前
0.2.22026/10/1622 天前
0.0.0-canary.esql-canary.c93c81b.1791235863canary-esql-canary2026/10/061 个月前
0.2.12026/10/051 个月前
0.0.0-canary.esql-canary.f7f39ac.17909891272026/10/031 个月前
0.0.0-canary.ci-publish-canary-npm.f53dfdc.1790988617canary-ci-publish-canary-npm2026/10/031 个月前

关于 @aws-blocks/bb-dashboard 的常见问题

@aws-blocks/bb-dashboard 是什么?

Auto-generated CloudWatch Dashboard for application observability.

如何安装 @aws-blocks/bb-dashboard?

在项目目录运行 npm install @aws-blocks/bb-dashboard,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.6.0)、aws-cdk-lib(^2.245.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws-blocks/bb-dashboard 支持 TypeScript 吗?

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

@aws-blocks/bb-dashboard 支持 ESM 还是 CommonJS?

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

@aws-blocks/bb-dashboard 可以商用吗?

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

@aws-blocks/bb-dashboard 的下载量有多少?

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

@aws-blocks/bb-dashboard 还在维护吗?

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