为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 go1.x 的 lambda 容器映像中将解组事件用于 AWS 定义的类型,并提供为基础

如何在 go1.x 的 lambda 容器映像中将解组事件用于 AWS 定义的类型,并提供为基础

Go
慕虎7371278 2022-10-17 15:52:04
我使用 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{}requestevents.APIGatewayProxyRequest


查看完整回答
反对 回复 2022-10-17
  • 1 回答
  • 0 关注
  • 104 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号