I am using aws-cdk for TypeScript.
I have an ApiGatewayv2 HttpApi with the following config:
new HttpApi(this, "Api", {
defaultIntegration: new LambdaProxyIntegration({
handler: new NodejsFunction(this, "Handler", {
handler: "handler",
entry: `${__dirname}/api-default.handler.ts`
}),
payloadFormatVersion: PayloadFormatVersion.VERSION_2_0
}),
createDefaultStage: true,
corsPreflight: {
allowHeaders: ['Authorization'],
allowMethods: [HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.POST],
allowOrigins: ['*'],
maxAge: Duration.days(10),
}
})
When I make a request to the API passing query parameters (using Postman) I see them in the handler payload attributes queryStringParameters
and rawQueryString
.
E.g. I make a GET request to https://MY_API_HASH.execute-api.eu-west-1.amazonaws.com?param=foo
the event, received in the Lambda handler looks like:
{
...
"rawQueryString": "param=foo",
...
"queryStringParameters": {
"param": "foo"
},
...
}
I made a Cloudfront Distribution with the following config:
new Distribution(this, "Distribution", {
defaultBehavior: {
origin: new S3Origin(bucket)
},
additionalBehaviors: {
"api": {
origin: new HttpOrigin(api.url!.split("/")[2]),
originRequestPolicy: new OriginRequestPolicy(this, "ApiOriginRequestPolicy", {
headerBehavior: OriginRequestHeaderBehavior.all(),
queryStringBehavior: OriginRequestQueryStringBehavior.all(),
}),
allowedMethods: AllowedMethods.ALLOW_ALL,
viewerProtocolPolicy: ViewerProtocolPolicy.ALLOW_ALL
}
}
})
When I make a request to the API through the Distribution URL I don't see in the payload
"rawQueryString": ""
and no queryStringParameters
How can I pass query parameters to the API handler when requesting the Cloudfront Distribution URL?
question from:
https://stackoverflow.com/questions/65952273/how-to-pass-query-parameters-to-apigateway-v2-httpapi-through-cloudfront-distrib