Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass query params from cloudfront to api gateway

I created a lambda function with a API gateway and Cloudfront distribution in the front

in the cloudfront behaviors I disabled caching

enter image description here

this is the lambda function:

exports.handler = async (event) => {
    const response = {
        statusCode: 200,
        body: JSON.stringify('rawQueryString is: ' + event.rawQueryString),
    };
    return response;
};

calling the api gateway I see the querystring in the lambda response https://xxx.execute-api.us-east-1.amazonaws.com/api?name=john

rawQueryString is: '?name=john'

calling the cloudfront distribution i can't see the querystring in the lambda response https://xxx.cloudfront.net/api?name=john

rawQueryString is: ''

I tried with "Origin Request Policy"

enter image description here

but now when i call https://xxx.cloudfront.net/api?name=john

I get

{
    "message": "Forbidden"
}
like image 575
handsome Avatar asked Oct 23 '25 04:10

handsome


1 Answers

You should setup origin request policies for your cache behavior. You can try with AWS managed Managed-AllViewer policy or create new one just to forward the query strings:

enter image description here

like image 57
Marcin Avatar answered Oct 25 '25 17:10

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!