2
votes

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"
}
1
Can you post more details? - jellycsc
updated. hope it helps. not much info honestly. is there anything in particular you want to see? - handsome

1 Answers

4
votes

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