@aws-amplify/ai-constructs

中文文档
1.7.0发布于 2026/09/10Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 6.3万

This package vends L3 CDK Constructs that deploy resources which power AI routes in Amplify apps.

原始使用文档
文档目录3 节
  1. Examples
  2. Default implementation
  3. Custom implementation

Description

This package vends L3 CDK Constructs that deploy resources which power AI routes in Amplify apps.

Conversation Handler Function

Conversation Handler Function L3 CDK Construct provisions resources required to integrate conversation routes (i.e. defined with a.ai.conversation() from @aws-amplify/data-schema) with AI models provided by AWS Bedrock service.

Resources deployed by this construct include:

  1. AWS Lambda function that:
    1. Accepts conversation turn events coming from upstream AWS AppSync instance that is hosting conversation routes in a form of GraphQL schemas.
    2. Interacts with AWS Bedrock to elicit a response to current conversation turn.
    3. Sends back the response to the same AWS AppSync instance in a form of GraphQL mutation.
  2. AWS CloudWatch Log Group associated with AWS Lambda function with addition of appropriate data protection policy.
  3. AWS IAM Policy that grants access to selected AWS Bedrock models.

This construct is used implicitly by @aws-amplify/data-construct when conversational routes don't specify handler reference. In this case default implementation provided by Amplify is deployed.

Alternatively, a custom lambda implementation can be provided by explicitly including this construct in backend definition and referencing it in schema.

Examples

Default implementation

import { App, Stack } from 'aws-cdk-lib';
import { ConversationHandlerFunction } from '@aws-amplify/ai-constructs/conversation';

const app = new App();
const stack = new Stack(app, 'ConversationHandlerStack');

new ConversationHandlerFunction(stack, {
  models: [
    {
      modelId: 'anthropic.claude-3-haiku-20240307-v1:0',
      region: 'us-east-1',
    },
  ],
});

Custom implementation

import { App, Stack } from 'aws-cdk-lib';
import { ConversationHandlerFunction } from '@aws-amplify/ai-constructs/conversation';
import path from 'path';

const app = new App();
const stack = new Stack(app, 'ConversationHandlerStack');

new ConversationHandlerFunction(stack, {
  entry: path.resolve('./custom_handler.ts'),
  models: [
    {
      modelId: 'anthropic.claude-3-haiku-20240307-v1:0',
      region: 'us-east-1',
    },
  ],
});

版本与发布记录

@aws-amplify/ai-constructs 共发布 88 个版本,首次发布于 2024/08/07;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.7.0latest2026/09/101 个月前
1.6.32026/09/072 个月前
0.0.0-iac-hosting-20260609205023iac-hosting2026/06/104 个月前
0.0.0-iac-hosting-202606091454172026/06/094 个月前
0.0.0-iac-hosting-202606051244592026/06/055 个月前
0.0.0-iac-hosting-202606051240112026/06/055 个月前

其他发布通道:test → 0.0.0-test-20260526153030,iac-hosting → 0.0.0-iac-hosting-20260609205023。

关于 @aws-amplify/ai-constructs 的常见问题

@aws-amplify/ai-constructs 是什么?

This package vends L3 CDK Constructs that deploy resources which power AI routes in Amplify apps.

如何安装 @aws-amplify/ai-constructs?

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

@aws-amplify/ai-constructs 支持 TypeScript 吗?

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

@aws-amplify/ai-constructs 支持 ESM 还是 CommonJS?

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

@aws-amplify/ai-constructs 可以商用吗?

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

@aws-amplify/ai-constructs 的下载量有多少?

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

@aws-amplify/ai-constructs 还在维护吗?

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