I'm using the HttpApi (Api Gateway) with a HttpAlbIntegration to connect to my backend. My backend requires a X-API-KEY header with a value comming from a custom claim in the JWT. So my setup is something like this:
const integration = new HttpAlbIntegration(`http-alb-integration`, albListener, {
method: HttpMethod.ANY,
vpcLink: vpcLinkStack.vpcLink,
parameterMapping: new ParameterMapping()
.appendHeader('x-api-key', MappingValue.contextVariable("authorizer.claims['custom:api_key']")
});
According to this https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html, it should work, but cdk complains about:
Invalid mapping expression specified: Validation Result: warnings : [], errors :
[Invalid mapping expression specified: $context.authorizer.claims['custom:api_key']]
All the other claims work fine: email and sub for instance. The problem only happens with custom attributes, I'm guessing because of the sintax that includes a :. I've tried different sintax alternatives, no luck. The straight question is:
how can I access custom claims from cognito authorizer in HttpApi integration?