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
asked 9 months ago507 views
1 Answer
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
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions