CloudFront 到 Lambda 函数 URL 的事件架构是什么

问题描述 投票:0回答:1

我使用 Lambda 函数 URL 作为 CloudFront 分配的来源。仅供参考,Lambda 函数使用 Go 1.20(在provided.al2 和 Arm64 上)。似乎工作正常,但我在发出请求时无法检索代码中的查询参数,例如“https://www.example.com?test=1234”。

CloudWatch 日志示例:

我将事件转储到的对象示例:

type Request struct {
    Context               Context        `json:"context"`
    Version               string         `json:"version"`
    RouteKey              string         `json:"routeKey"`
    RawPath               string         `json:"rawPath"`
    RawQueryString        string         `json:"rawQueryString"`
    Cookies               []string       `json:"cookies"`
    Headers               cli.StringMap  `json:"headers"`
    QueryStringParameters cli.StringMap  `json:"queryStringParameters"`
    QueryString           cli.StringMap  `json:"querystring"`
    RequestContext        RequestContext `json:"requestContext"`
    Body                  string         `json:"body"`
    PathParameters        interface{}    `json:"pathParameters"`
    IsBase64Encoded       bool           `json:"isBase64Encoded"`
    StageVariables        interface{}    `json:"stageVariables"`
}

虽然我应该切换到这个:https://github.com/aws/aws-lambda-go/blob/v1.41.0/events/lambda_function_urls.go#L14C39-L14C39

是的,我已允许 CloudFront 请求策略中的所有查询字符串:

我还删除了所有 CloudFront 和 Lambda@Edge 函数,直到我通过此测试。

问题是我不确定 CloudFront 调用 Lambda 函数 URL 时使用的是哪种事件请求格式。到目前为止我读过的所有 AWS 文档都没有说清楚。我有多种选择:

  1. https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads
  2. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-struct.html

我也没有看到可以在官方 AWS Lambda Go 包中使用的官方 CloudFront 事件,网址为 https://pkg.go.dev/github.com/aws/aws-lambda-go/events#section -自述文件

amazon-web-services aws-lambda amazon-cloudfront
1个回答
0
投票

您可以使用AWS官方的Lambda Function urls types。我删除了我的请求类型,转而使用请求和响应类型,一切开始工作。

我禁用了 CloudFront 缓存,然后更新了 Lambda 包,一切都开始工作了。

© www.soinside.com 2019 - 2024. All rights reserved.