CloudFront Function event.request.uri contains query params

0

Hi

I have the following as my CloudFront Function:

function handler(event) {
    console.log(event);
    return event.request;
}

In the CloudFront console, I switch to the Test tab, and use this as URL path: /1234?param=1. When I run the test request and inspect the logs, I see the following:

{
   "version":"1.0",
   "context":{
      "distributionDomainName":"[redacted].cloudfront.net",
      "distributionId":"[redacted]",
      "eventType":"viewer-request",
      "requestId":"4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=="
   },
   "viewer":{
      "ip":"1.2.3.4"
   },
   "request":{
      "method":"GET",
      "uri":"/index.html?q:1",
      "querystring":{
      },
      "headers":{
      },
      "cookies":{
      }
   }
}

In the Test tab GUI, if I add the params to "Query string" section, it works fine. But when I execute the request from different clients, say a browser, the query params are actually part of the event.request.uri instead of event.request.querystring.

We're expecting the params to be part of the querystring object, is this not true? Is there some sort of configurations to parse these correctly?

I have added the following screen grabs if it would help:

Enter image description here Enter image description here

Ennabah
已提问 10 个月前574 查看次数
1 回答
0

Thank you for the details. Via the Test tab GUI, it's correct to add the params to Query string section.

When you are sending requests from other clients, the query parameters should as well reside in querystring field as explained in this document. This can be verified by deploying the function to LIVE stage and looking into the edge function logs.

(as is adding the params to Query string section in the Test tab GUI)

AWS
weidi
已回答 10 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则