[AWS] Solve Error: Lambda Options Request UnAuthorized


If you configure CORS (Cross-Origin Resource Sharing) for an API, API Gateway automatically sends a response to preflight OPTIONS requests, even if there isn't an OPTIONS route configured for your API.

At this time, you might want to disable your OPTIONS request authorizer, otherwise the preflight call might get unauthorized. You can disable it when define your authorizers in the SAM (Serverless Application Model) template by adding AddDefaultAuthorizerToCorsPreflight: False. For example:

Auth:
  DefaultAuthorizer: MyLambdaTokenAuthorizer
  Authorizers:
    MyLambdaTokenAuthorizer:
      FunctionArn: !GetAtt ValidateTokenFunction.Arn
  AddDefaultAuthorizerToCorsPreflight: False

Refereces:

Configuring CORS for an HTTP API

posted @ 2022-06-19 04:54  Grandyang  阅读(55)  评论(0编辑  收藏  举报
Fork me on GitHub