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

使用AWS Lambda RIE测试Go函数时Curl请求超时问题排查

问题分析与解决

核心问题:启动命令错误

你直接用~/.aws-lambda-rie/aws-lambda-rie go run main.go运行Go源码是错误的——Lambda Runtime Interface Emulator(RIE)需要调用编译后的Go二进制可执行文件,而非通过go run动态运行源码。go run会在临时目录生成二进制,RIE无法正确与它交互,最终导致请求超时。

正确操作步骤

  1. 编译Go Lambda函数
    在项目目录下执行编译命令,生成适配Lambda Linux环境的二进制文件:

    GOOS=linux GOARCH=amd64 go build -o main main.go
    

    这里-o main指定输出的二进制文件名为main,也就是Lambda的handler名称。

  2. 用RIE启动编译后的二进制
    执行以下命令启动RIE和Lambda函数:

    ~/.aws-lambda-rie/aws-lambda-rie ./main
    
  3. 重新发起curl请求
    在另一个终端执行:

    curl -XGET http://localhost:8080/2015-03-31/functions/function/invocations
    

额外检查点

  • Handler签名修正:你当前的Handler签名func Handler() (events.APIGatewayProxyResponse, error)不符合Lambda Go运行时规范,正确的APIGateway代理事件Handler需要包含输入参数:

    func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
        response := events.APIGatewayProxyResponse{
            StatusCode: 200,
            Body:       "Hello World",
        }
        log.Print(response.Body)
        return response, nil
    }
    

    虽然缺少参数在本地RIE测试中不会直接导致超时,但部署到Lambda时会触发错误,建议提前修正。

  • 日志警告说明:日志里的Cannot list external agents和extensionsDisabledByLayer属于正常警告,因为你没有使用Lambda扩展,完全不影响函数运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 11:17:24