簡體   English   中英

使用 SAM 模板部署 api 網關時出現 cors 錯誤

[英]Getting cors error when api gateway deployed using SAM template

我在 node.js 中開發了 lambda 功能,並嘗試使用 SAM 模板部署到api 網關,並使用代理集成 我的 lambda 函數正在返回標頭,如 AWS 文檔中所述

const response = {
       statusCode: 200,
       headers: {
           "Access-Control-Allow-Headers" : "Content-Type",
           "Access-Control-Allow-Origin": "https://www.example.com",
           "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
       },
       body: JSON.stringify('Hello from Lambda!'),
   };

模板.yaml代碼

GetClientFunction:
      Type: AWS::Serverless::Function
      Properties:
        CodeUri: functions/GetClient/
        Handler: index.handler
        Runtime: nodejs14.x
      Events:
        GetClientCustomFieldMap:
          Type: Api
          Properties:
            RestApiId: !Ref ClientApi # this is api with authorizer configured
            Path: api/Client/GetClient/{name}   
            Method: get

它正在創建路徑中提到的所有資源,如“api”、“Client”、“GetClient”,但不是使用Options方法,還會出現 cors 錯誤。 從 stackoverflow 嘗試了多種方法,但無法解決。 遵循這個 url 以及如何使用 AWS SAM 啟用 CORS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM