我使用 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 關注
- 88 瀏覽
添加回答
舉報
0/150
提交
取消