我使用 API Gatway 通过代理集成触发 Lambda我从 public.ecr.aws/lambda/provided:al2 为 Golang 构建了一个 lambda 容器映像,因为无法在 public.ecr.aws/lambda/go:latest 中安装依赖关系。Docerfile我的内容的 PFBFROM public.ecr.aws/lambda/provided:al2COPY ./config/yumrepo/dep1.repo /etc/yum.repos.d/dep1.repoCOPY ./config/yumrepo/dep2.repo /etc/yum.repos.d/dep2.repoRUN yum install -y dep1 dep2COPY --from=build /main /var/runtime/bootstrap # If I dont copy to bootstrap the lambda is not starting upCMD [ "handler" ]我面临的问题是事件处于编组状态。如果我对预期函数的 lambda 进行 api 调用,events.APIGatewayProxyRequest由于输入的类型是map[string]interface{}.我的猜测是,这与运行时接口客户端和引导程序有关。我从AWS Lambda 指南中获得了相同的以下参考AWS 没有为 Go 提供单独的运行时接口客户端。aws-lambda-go/lambda 包包含运行时接口的实现。上面的图像得到构建,并使用以下代码使 API 工作。func (h *Handler) HandleRequest(ctx context.Context, request interface{}) (interface{}, error) { requestMap := request.(map[string]interface{}) _, ok := getMapValue(requestMap, "headers") if ok { httpMethod, _ := getStringValue(requestMap, "httpMethod") resource, _ := getStringValue(requestMap, "resource") body, _ := getStringValue(requestMap, "body") requestObj := events.APIGatewayProxyRequest{ Body: body, IsBase64Encoded: false, Resource: resource, HTTPMethod: httpMethod, } return h.HandleAPIRequest(ctx, requestObj) } return nil, fmt.Errorf("unknown request type")}这是构建图像的正确方法以及如何在我的代码中以 AWS 定义的类型接收事件吗?
1 回答

当年话下
TA贡献1890条经验 获得超9个赞
发现问题
因为处理函数期望interface
在我将参数 的类型更改为我的代码自动开始以这种类型接收之后request
传递。map[string]interface{}
request
events.APIGatewayProxyRequest
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消