我使用 API Gatway 通過代理集成觸發(fā) Lambda我從 public.ecr.aws/lambda/provided:al2 為 Golang 構(gòu)建了一個(gè) lambda 容器映像,因?yàn)闊o法在 public.ecr.aws/lambda/go:latest 中安裝依賴關(guān)系。Docerfile我的內(nèi)容的 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" ]我面臨的問題是事件處于編組狀態(tài)。如果我對(duì)預(yù)期函數(shù)的 lambda 進(jìn)行 api 調(diào)用,events.APIGatewayProxyRequest由于輸入的類型是map[string]interface{}.我的猜測(cè)是,這與運(yùn)行時(shí)接口客戶端和引導(dǎo)程序有關(guān)。我從AWS Lambda 指南中獲得了相同的以下參考AWS 沒有為 Go 提供單獨(dú)的運(yùn)行時(shí)接口客戶端。aws-lambda-go/lambda 包包含運(yùn)行時(shí)接口的實(shí)現(xiàn)。上面的圖像得到構(gòu)建,并使用以下代碼使 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")}這是構(gòu)建圖像的正確方法以及如何在我的代碼中以 AWS 定義的類型接收事件嗎?
1 回答

當(dāng)年話下
TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
發(fā)現(xiàn)問題
因?yàn)樘幚砗瘮?shù)期望interface
在我將參數(shù) 的類型更改為我的代碼自動(dòng)開始以這種類型接收之后request
傳遞。map[string]interface{}
request
events.APIGatewayProxyRequest
- 1 回答
- 0 關(guān)注
- 102 瀏覽
添加回答
舉報(bào)
0/150
提交
取消