AIP-C01 练习题

AIP-C01 题目讲解:流式展示必须真的把 chunks 送前端

AIP-C01 练习题讲解。答案 B。完整缓冲后返回不能降低首段文字等待时间。

AIP-C01 免费试练题 · 考证匠讲解

题目

A developer is building a customer-facing chatbot using Amazon Bedrock and Amazon API Gateway. The Large Language Model (LLM) responses can take several seconds to generate completely. To improve user experience, the frontend application requires the text to appear character-by-character as it is generated. Which architecture achieves this with the LOWEST latency?

A. Configure an Amazon API Gateway REST API. Use an AWS Lambda function to invoke the Bedrock model with invoke_model. Buffer the response in Lambda and return the complete JSON object to API Gateway.
B. Configure an Amazon API Gateway WebSocket API. Use an AWS Lambda function to invoke the Bedrock model using invoke_model_with_response_stream. Iterate through the event stream chunks and send them to the connection ID using the PostToConnection API.
C. Configure an Amazon API Gateway REST API. Use an AWS Lambda function to invoke the Bedrock model using invoke_model_with_response_stream. Return the stream object directly to the API Gateway to utilize REST API response streaming.
D. Configure an Amazon Kinesis Data Stream to capture user requests. Use an AWS Lambda consumer to invoke Bedrock. Write the output chunks to an Amazon DynamoDB table. Have the frontend poll DynamoDB for new chunks.

答案

答案 B。完整缓冲后返回不能降低首段文字等待时间。

拆题

  • 完整缓冲后返回不能降低首段文字等待时间。
  • WebSocket 持续连接配 PostToConnection 能把 Bedrock chunks 主动送客户端。
  • 当前 API Gateway REST 也支持配置 response streaming;C 错在“直接返回 SDK stream object”不是完整有效 Lambda streaming 集成,不能说 REST 永远不支持。

每个选项为什么对、为什么错

  • A:invoke_model 后缓冲整段,首字要等全部生成,违背流式体验。
  • B(正确):逐 chunk 读取响应并发送到 connection ID,提供明确可实现的数据推送链路;chunk 不一定恰好一个字符,前端可按片段渲染。
  • C:REST streaming 现在可行,但需要正确 integration transfer mode 与 Lambda streaming 格式;Python SDK 流对象直接 return 通常不能序列化并建立完整流。
  • D:Kinesis、DynamoDB 与轮询增加存储和轮询等待,多层不必要开销。

放到具体场景里

教学例子:前端发 prompt 并保留 WebSocket,Lambda 每收到 text delta 就发送带 sequence 的消息,前端追加文字,最后发 done。断连时处理 GoneException、超时和取消,不能持续写无效 connection。比较 time-to-first-token 和完整响应时间,流式不一定缩短总生成时间。

检查对象本例条件或动作结果与边界
模型输出text delta chunks非固定单字符
通道WebSocket PostToConnection处理断连
指标首 token 与总时长体验和总耗时分开

遇到同类题的判断顺序

  1. 建立连接:保存受授权 connection ID。
  2. 调用流接口:读取模型事件。
  3. 逐片发送:带顺序和终止标记。
  4. 处理断连:取消或停止无效推送。
结论:B 是完整描述路径;REST 流式需要正确配置,不能直接返回 SDK 对象。

参考资料

继续练这门考试

同一门考试的免费试练题都附这样的完整讲解,做完再看讲解。