403 on Options request within SAM local invoke, but not when deployed?

Why does curl say “missing auth token”? As far as I know I definitely enabled the options method to return a default 200. I definitely have "AuthorizationType": "NONE" in my options setup.

I am running a frontend via set PORT=4000 && react-scripts start and a backend with sam local start-api --template lambdas_sam.json.

When I test the options method via curl I get:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>curl -i -X OPTIONS http://127.0.0.1:3000/scanRecords -H "Origin: http://localhost:4000" -H "Access-Control-Request-Method: POST"
HTTP/1.1 403 FORBIDDEN
Server: Werkzeug/3.0.1 Python/3.11.8
Date: Wed, 11 Sep 2024 02:47:58 GMT
Content-Type: application/json
Content-Length: 43
Connection: close
{"message":"Missing Authentication Token"}
</code>
<code>curl -i -X OPTIONS http://127.0.0.1:3000/scanRecords -H "Origin: http://localhost:4000" -H "Access-Control-Request-Method: POST" HTTP/1.1 403 FORBIDDEN Server: Werkzeug/3.0.1 Python/3.11.8 Date: Wed, 11 Sep 2024 02:47:58 GMT Content-Type: application/json Content-Length: 43 Connection: close {"message":"Missing Authentication Token"} </code>
curl -i -X OPTIONS http://127.0.0.1:3000/scanRecords -H "Origin: http://localhost:4000" -H "Access-Control-Request-Method: POST"

HTTP/1.1 403 FORBIDDEN
Server: Werkzeug/3.0.1 Python/3.11.8
Date: Wed, 11 Sep 2024 02:47:58 GMT
Content-Type: application/json
Content-Length: 43
Connection: close

{"message":"Missing Authentication Token"}

lambdas_sam.json snippet:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"scanRecords": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "dist/dynamo/CRUD.scanRecords",
"CodeUri": "./backend",
"Policies": [
"AmazonDynamoDBFullAccess",
"CloudWatchLogsFullAccess"
],
"Events": {
"0": {
"Type": "Api",
"Properties": {
"Path": "/scanRecords",
"Method": "post"
}
}
}
}
},
"scanRecordsResource": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"ParentId": {
"Fn::GetAtt": [
"apiGatewayRestApi",
"RootResourceId"
]
},
"PathPart": "scanRecords",
"RestApiId": {
"Ref": "apiGatewayRestApi"
}
}
},
"scanRecordsGatewayMethod": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "COGNITO_USER_POOLS",
"AuthorizerId": {
"Ref": "CognitoAuthorizer"
},
"HttpMethod": "post",
"Integration": {
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Sub": [
"arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${lambdaArn}/invocations",
{
"lambdaArn": {
"Fn::GetAtt": [
"scanRecords",
"Arn"
]
}
}
]
}
},
"ResourceId": {
"Ref": "scanRecordsResource"
},
"RestApiId": {
"Ref": "apiGatewayRestApi"
}
}
},
"scanRecordsOptionsMethod": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
"HttpMethod": "OPTIONS",
"ResourceId": {
"Ref": "scanRecordsResource"
},
"RestApiId": {
"Ref": "apiGatewayRestApi"
},
"Integration": {
"Type": "MOCK",
"IntegrationResponses": [
{
"StatusCode": 200,
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
"method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",
"method.response.header.Access-Control-Allow-Origin": "'*'"
},
"ResponseTemplates": {
"application/json": ""
}
}
],
"PassthroughBehavior": "WHEN_NO_MATCH",
"RequestTemplates": {
"application/json": "{}"
}
},
"MethodResponses": [
{
"StatusCode": 200,
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Headers": true,
"method.response.header.Access-Control-Allow-Methods": true,
"method.response.header.Access-Control-Allow-Origin": true
}
}
]
}
},
"ApiGatewayInvokeLambdaPermissionscanRecords": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"scanRecords",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGatewayRestApi}/*/*/*"
}
}
}
</code>
<code>"scanRecords": { "Type": "AWS::Serverless::Function", "Properties": { "Handler": "dist/dynamo/CRUD.scanRecords", "CodeUri": "./backend", "Policies": [ "AmazonDynamoDBFullAccess", "CloudWatchLogsFullAccess" ], "Events": { "0": { "Type": "Api", "Properties": { "Path": "/scanRecords", "Method": "post" } } } } }, "scanRecordsResource": { "Type": "AWS::ApiGateway::Resource", "Properties": { "ParentId": { "Fn::GetAtt": [ "apiGatewayRestApi", "RootResourceId" ] }, "PathPart": "scanRecords", "RestApiId": { "Ref": "apiGatewayRestApi" } } }, "scanRecordsGatewayMethod": { "Type": "AWS::ApiGateway::Method", "Properties": { "AuthorizationType": "COGNITO_USER_POOLS", "AuthorizerId": { "Ref": "CognitoAuthorizer" }, "HttpMethod": "post", "Integration": { "IntegrationHttpMethod": "POST", "Type": "AWS_PROXY", "Uri": { "Fn::Sub": [ "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${lambdaArn}/invocations", { "lambdaArn": { "Fn::GetAtt": [ "scanRecords", "Arn" ] } } ] } }, "ResourceId": { "Ref": "scanRecordsResource" }, "RestApiId": { "Ref": "apiGatewayRestApi" } } }, "scanRecordsOptionsMethod": { "Type": "AWS::ApiGateway::Method", "Properties": { "AuthorizationType": "NONE", "HttpMethod": "OPTIONS", "ResourceId": { "Ref": "scanRecordsResource" }, "RestApiId": { "Ref": "apiGatewayRestApi" }, "Integration": { "Type": "MOCK", "IntegrationResponses": [ { "StatusCode": 200, "ResponseParameters": { "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'", "method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": "'*'" }, "ResponseTemplates": { "application/json": "" } } ], "PassthroughBehavior": "WHEN_NO_MATCH", "RequestTemplates": { "application/json": "{}" } }, "MethodResponses": [ { "StatusCode": 200, "ResponseParameters": { "method.response.header.Access-Control-Allow-Headers": true, "method.response.header.Access-Control-Allow-Methods": true, "method.response.header.Access-Control-Allow-Origin": true } } ] } }, "ApiGatewayInvokeLambdaPermissionscanRecords": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ "scanRecords", "Arn" ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGatewayRestApi}/*/*/*" } } } </code>
"scanRecords": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Handler": "dist/dynamo/CRUD.scanRecords",
        "CodeUri": "./backend",
        "Policies": [
          "AmazonDynamoDBFullAccess",
          "CloudWatchLogsFullAccess"
        ],
        "Events": {
          "0": {
            "Type": "Api",
            "Properties": {
              "Path": "/scanRecords",
              "Method": "post"
            }
          }
        }
      }
    },
    "scanRecordsResource": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
        "ParentId": {
          "Fn::GetAtt": [
            "apiGatewayRestApi",
            "RootResourceId"
          ]
        },
        "PathPart": "scanRecords",
        "RestApiId": {
          "Ref": "apiGatewayRestApi"
        }
      }
    },
    "scanRecordsGatewayMethod": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "AuthorizationType": "COGNITO_USER_POOLS",
        "AuthorizerId": {
          "Ref": "CognitoAuthorizer"
        },
        "HttpMethod": "post",
        "Integration": {
          "IntegrationHttpMethod": "POST",
          "Type": "AWS_PROXY",
          "Uri": {
            "Fn::Sub": [
              "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${lambdaArn}/invocations",
              {
                "lambdaArn": {
                  "Fn::GetAtt": [
                    "scanRecords",
                    "Arn"
                  ]
                }
              }
            ]
          }
        },
        "ResourceId": {
          "Ref": "scanRecordsResource"
        },
        "RestApiId": {
          "Ref": "apiGatewayRestApi"
        }
      }
    },
    "scanRecordsOptionsMethod": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "AuthorizationType": "NONE",
        "HttpMethod": "OPTIONS",
        "ResourceId": {
          "Ref": "scanRecordsResource"
        },
        "RestApiId": {
          "Ref": "apiGatewayRestApi"
        },
        "Integration": {
          "Type": "MOCK",
          "IntegrationResponses": [
            {
              "StatusCode": 200,
              "ResponseParameters": {
                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
                "method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",
                "method.response.header.Access-Control-Allow-Origin": "'*'"
              },
              "ResponseTemplates": {
                "application/json": ""
              }
            }
          ],
          "PassthroughBehavior": "WHEN_NO_MATCH",
          "RequestTemplates": {
            "application/json": "{}"
          }
        },
        "MethodResponses": [
          {
            "StatusCode": 200,
            "ResponseParameters": {
              "method.response.header.Access-Control-Allow-Headers": true,
              "method.response.header.Access-Control-Allow-Methods": true,
              "method.response.header.Access-Control-Allow-Origin": true
            }
          }
        ]
      }
    },
    "ApiGatewayInvokeLambdaPermissionscanRecords": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Fn::GetAtt": [
            "scanRecords",
            "Arn"
          ]
        },
        "Principal": "apigateway.amazonaws.com",
        "SourceArn": {
          "Fn::Sub": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGatewayRestApi}/*/*/*"
        }
      }
    }

1

AFAIK the Cognito authorizer is not supported yet in aws-sam-cli for local testing, the only supported authorizer in local mode is the lambda authoizer.

In the code we can see:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>LOG.debug("Authorizer '%s' is currently unsupported (must be a Lambda Authorizer), skipping", auth_name)
</code>
<code>LOG.debug("Authorizer '%s' is currently unsupported (must be a Lambda Authorizer), skipping", auth_name) </code>
LOG.debug("Authorizer '%s' is currently unsupported (must be a Lambda Authorizer), skipping", auth_name) 

Another way is to test resources deployed remotly with sam sync.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật