Question
What are the necessary steps to dynamically set headers in the response from API gateway using the context from the authorizer response.
Current Approach
Here are the current steps I have implemented to set the response header(s) dynamically.
- Dynamically generate the response header value in the authorizer-lambda and return it in the context of the authorizer response.
return {
principalId,
policyDocument: {
Version: "2012-10-17",
Statement: [
{
Action: "execute-api:Invoke",
Effect: effect,
Resource: this.resource(this.event.path),
},
],
},
context: {
dynamicValue: dynamicValue
},
};
- Configure the gateway response headers. (NOTE: This is where I an running into issues.)
- API Gateway → [Choose Gateway] → Gateway Responses → Unauthorized
- Add Response Header:
- Response Header:
x-new-header-value
- Value:
$context.authorizer.dynamicValue
- Response Header:
Problem(s)
When using the mapping template for the value in the step above I get the error below. This makes me think I am missing a configuration step.
Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: $context.authorizer.doLogout]