【问题标题】:IntegrationResponse SAM Template集成响应 SAM 模板
【发布时间】:2020-01-07 14:43:45
【问题描述】:

问题:

  • 对 Sam 模板的集成响应?没有 OpenApi 可以吗?
  • 如何在 SAM 模板中向 GatewayResponses 添加标头?

我想要达到的目标:

  • 在 SAM 中定义网关响应和集成响应 CloudFront 模板。

到目前为止我检查了什么:

我正在检查 SAM github,但对我来说,根据上面的链接不清楚如何做。 我也没有在 stackoverflow 上找到任何答案,这可以解释为什么我的 gatewayresponse sn-p 中的标头不好

感谢每一个帮助

一些例子:

Globals:
  Api:
    GatewayResponses:
      MISSING_AUTHENTICATION_TOKEN:
        ResponseParameters:
        #  gatewayresponse.header.Cache-Control: "no-cache"
        ResponseTemplates: 
          "application/json" : '{"errors": [{errorKey: "error Value"}]}'
        StatusCode: '404'
        #defaultResponse: true

预期的功能级集成响应:

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Handler: Function.handler
      Timeout: 20
      CodeUri: "src/Function"
      Role: .......
      Events:
        FunctionGet:
          Type: Api
          Properties:
            Path: /Function
            Method: get
            IntegrationResponse:
              SOME_ERROR_CODE
                ResponseTemplates
                  integrationresponse.header

【问题讨论】:

    标签: aws-lambda aws-api-gateway aws-sam


    【解决方案1】:

    长话短说,我的问题有一半是愚蠢的。在代理集成 API GW 中,默认将响应从服务器返回到客户端,无需在 SAM 模板中进一步声明。

    至于headers下面的方式是正确的:

    Globals:
      Api:
        GatewayResponses:
          MISSING_AUTHENTICATION_TOKEN:
            ResponseParameters:
              Headers:
                Access-Control-Allow-Origin: "'*'"
                Access-Control-Allow-Headers: "'*'"
                Cache-Control: "'no-cache'"
                Content-Type: "'application/json'"
            ResponseTemplates: 
               "application/json" : '{"errors": [{errorKey: "error Value"}]}'
            StatusCode: '404'
            #defaultResponse: true
    

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 2021-10-11
      • 2020-06-14
      • 2020-12-16
      • 2020-10-13
      • 2018-11-25
      • 2021-09-17
      • 1970-01-01
      • 2018-10-12
      相关资源
      最近更新 更多