rul*_*tra 3 go amazon-web-services aws-lambda aws-api-gateway
我有一个使用 API Gateway 调用的 lambda 函数。该函数通过以下代码使用 GET 方法来工作:
func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// add code here
return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}
func main() {
lambda.Start(handleRequest)
}
Run Code Online (Sandbox Code Playgroud)
我有这个event.APIGatewayProxyRequest和GET方法。但是当我尝试将 URL 迁移到Function URLs时,我没有类似的设置GET方法。URL 如何知道在 POSTMAN 中使用哪种方法?和...
我们有等效的方法来event.APIGatewayProxyRequest完成该请求吗?
当我使用 URL 调用它时,出现502 BAD GATEWAY错误。
bla*_*een 11
Lambda 函数 URL 的 AWS 事件是events.LambdaFunctionURLRequest以及相关类型。
所以你的处理程序签名应该如下所示:
func handleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
// add code here
return events.LambdaFunctionURLResponse{Body: request.Body, StatusCode: 200}, nil
}
Run Code Online (Sandbox Code Playgroud)
创建 Lambda 的 URL 后,调用者(例如 Postman)可以指定任何 HTTP 方法,您可以通过以下方式在处理程序中访问该方法:
// request is LambdaFunctionURLRequest
request.RequestContext.HTTP.Method
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1595 次 |
| 最近记录: |