AWS lambda的功能URL无API网关在GO中

发布于 2025-02-11 08:13:05 字数 778 浏览 2 评论 0 原文

我有一个由API网关调用的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)
}

我有此 event.apigatewayproxyrequest get 方法。但是,当我尝试将URL迁移到a ,我没有什么相似的设置 get 方法。 URL应该如何知道在邮递员中使用哪种方法?而且...

我们是否有 event.apigatewayproxyrequest 进行请求的等效内容?

当我用URL调用它时,我得到了 502 坏网关错误。

I have a lambda function that is invoked with API Gateway.
The function is working using the GET method with this code:

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)
}

I have this event.APIGatewayProxyRequest and GET method. But when I try to migrate the URL to a Function URLs, I have nothing similar to set the GET method. How was the URL supposed to know which method to use in the POSTMAN? and...

Do we have an equivalent for event.APIGatewayProxyRequest to do the request?

When I invoke it with URL, I got a 502 BAD GATEWAY error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2025-02-18 08:13:05

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
}

创建lambda的URL后,呼叫者(例如Postman)可以指定任何HTTP方法,您可以使用以下方式访问该方法:

// request is LambdaFunctionURLRequest
request.RequestContext.HTTP.Method

The AWS event for Lambda Function URL is events.LambdaFunctionURLRequest and the related types.

So your handler signature should look like:

func handleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
    // add code here
    return events.LambdaFunctionURLResponse{Body: request.Body, StatusCode: 200}, nil
}

Once you create the URL of your Lambda, the caller (e.g. Postman) can specify whatever HTTP method, which you can access inside your handler with:

// request is LambdaFunctionURLRequest
request.RequestContext.HTTP.Method
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文