Error: Unable to put integration response on ‘OPTIONS’ for resource at path ‘/{proxy+}’: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: ] (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;

OK. Let’s get started with this issue. I would like to define an API Gateway with my lambda function using AWS Serverless Application Model (AWS SAM). However I get the error (Error: Unable to put integration response on ‘OPTIONS’ for resource at path ‘/{proxy+}’: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: ] (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;) when I deploy my application using SAM yaml template.

After my investigation, I noticed that the incorrect quotation syntax is the root cause of this issue.

The original yaml file (with error) is below.

Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "*"
AllowHeaders: "*"

AllowOrigin: "www.example.com"
MaxAge: "600"
AllowCredentials: True

The updated yaml file is below.

Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"

AllowOrigin: "'www.example.com'"
MaxAge: "600"
AllowCredentials: True

Please note CORS configuration strings should have an extra pair of quotes like above example. And API Gateway requires literal values to be a quoted string, so don’t forget the additional quotes in the Allow___ values. ie. “‘www.example.com‘” is correct whereas “www.example.com” is wrong.

1 Comment

  • Rakesh February 22, 2021

    Thanks for this write up.

Leave a Reply