I have a lambda authorizer for my API Gateway authorization. When authorizer returns 401 or 403 I do not get CORS back in response header. I am using AWS::Serverless::Api
resource, and after some research found here that I need to set GatewayResponses
to return custom headers for 4XX responses.
My Api Gateway definition looks like:
resApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Sub "${env}"
EndpointConfiguration: !If [IsLocal, "REGIONAL", "EDGE"]
Cors:
AllowMethods: "'OPTIONS,GET,POST,PUT,DELETE'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization'"
AllowOrigin: "'*'"
GatewayResponses:
DEFAULT_4XX:
ResponseParameters:
"gatewayresponse.header.Access-Control-Allow-Origin": "'*'"
...
...
But I am getting error on cfn stack deployment:
Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [resApiGateway] is invalid. Invalid gateway response parameter 'gatewayresponse.header.Access-Control-Allow-Origin'
Headers:
underResponseParameters
) – Pinhead