You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为AWS Lambda Function URLs声明TypeScript Lambda处理器?

Lambda Function URLs触发的TypeScript Lambda代码示例

当Lambda函数通过Function URLs触发时,对应的TypeScript类型是APIGatewayProxyV2Handler,它同样来自@types/aws-lambda模块,等效代码如下:

import { APIGatewayProxyV2Handler } from "aws-lambda";

export const handler: APIGatewayProxyV2Handler = async (event, context) => {
  // 编写你的函数逻辑
  return {
    statusCode: 200,
    body: JSON.stringify({ message: "请求处理成功" })
  };
};

关键说明:

  • Lambda Function URLs的事件结构与API Gateway v2(HTTP API)的事件格式完全匹配,因此使用APIGatewayProxyV2Handler能正确约束event、context的类型,以及返回值的结构。
  • 示例中省略了callback参数,这是因为当前Lambda开发更推荐使用async/await的返回值方式来处理响应,替代传统的回调模式。

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 18:52:03