I’m trying to pass a literal value to the called lambda function using API gateway integration requestParameters
but with no luck.
My current code is:
myApigatewayResource.addMethod(
'GET',
new apiGateway.LambdaIntegration(
myLambdaFunctionHandler,
{
requestParameters: {
'integration.request.querystring.customvalue': '123456789'
}
}
),
{
methodResponses: [
{ statusCode: '200' },
]
}
);
When running cdk synth && cdk deploy
I get the error:
Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: 123456789
Official documentation for LambdaIntegrationOptions states:
Specify request parameters as key-value pairs (string-to-string mappings), with a destination as the key and a source as the value.
Specify the destination by using the following pattern integration.request.location.name, where location is querystring, path, or header, and name is a valid, unique parameter name.
The source must be an existing method request parameter or a static value. You must enclose static values in single quotation marks and pre-encode these values based on their destination in the request.
My code looks compliant with what stated since I used ‘integration.request.querystring.customvalue’ as destination/key and a static value enclosed in single quotes as source/value.
Where is the problem?
2
Answers
It means that the value itself as it gets published to CloudFormation stack and later to API Gateway should be enclosed in single quotation marks.
The quotation marks in
'123456789'
are a part of the JavaScript code. The value defined with this code is the string123456789
, without the quotation marks.Try this:
Some time ago I has a similar issue. So, you can’t directly pass a hard-coded, literal value through
requestParameters
. You need to set a default value for a query parameter in your API Gateway method, and then map this parameter to your Lambda function.The
addMethodResponse
andaddIntegrationResponse
set up a default value for a response header.P.S. I did not deploy this code, so please let me know if it’s work π