I have a custom authorizer that emits context information that I’d like to pass in a header to an HTTP API backend.
According to the AWS docs, I should be able to reference context.authorizer.key
in the request integration headers, like this:
As a new user, I don’t have sufficient karma to post all the links / images for the research I’ve done, so this will be a bit awkward.
I’ve tried poking around and have even dug into the code, but it doesn’t seem like there is a way to do what I’m describing with the current Serverless AWS provider. Using:
events:
- http:
path: /echo
method: get
authorizer:
name: authorizer
type: request
integration: http-proxy
request:
uri: https://example.com/
method: get
parameters:
headers:
SomeKey: context.authorizer.someKey
really doesn’t work, as it creates a Method Request header definition that looks like this:
HTTP Request Headers
Name Required Caching
SomeKey [ ] [ ]
and an Integration Request definition that looks like this:
Name Mapped From Caching
SomeKey method.request.header.SomeKey [ ]
The relevant bit in the CloudFormation seems to be:
"ApiGatewayMethodEchoGet": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"RequestParameters": {
"method.request.header.SomeKey": "context.authorizer.someKey"
},
"ResourceId": {
"Ref": "ApiGatewayResourceEcho"
},
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"ApiKeyRequired": false,
"AuthorizationType": "CUSTOM",
"AuthorizerId": {
"Ref": "AuthorizerApiGatewayAuthorizer"
},
"Integration": {
"IntegrationHttpMethod": "GET",
"Type": "HTTP_PROXY",
"Uri": "https://example.com/",
"RequestParameters": {
"integration.request.header.SomeKey": "method.request.header.SomeKey"
}
},
"MethodResponses": []
},
"DependsOn": "AuthorizerApiGatewayAuthorizer"
},
which I think should look more like this:
"ApiGatewayMethodEchoGet": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"RequestParameters": {
},
"ResourceId": {
"Ref": "ApiGatewayResourceEcho"
},
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"ApiKeyRequired": false,
"AuthorizationType": "CUSTOM",
"AuthorizerId": {
"Ref": "AuthorizerApiGatewayAuthorizer"
},
"Integration": {
"IntegrationHttpMethod": "GET",
"Type": "HTTP_PROXY",
"Uri": "https://example.com/",
"RequestParameters": {
"integration.request.header.SomeKey": "context.authorizer.someKey"
}
},
"MethodResponses": []
},
"DependsOn": "AuthorizerApiGatewayAuthorizer"
},
The serverless docs page for API Gateway is silent on this topic.
What am I missing?