IntegrationResponse SAM模板

huangapple go评论100阅读模式
英文:

IntegrationResponse SAM Template

问题

  • IntegrationResponse to Sam template ? Is it possible without OpenApi?

    • 将IntegrationResponse添加到SAM模板中?是否可以在没有OpenApi的情况下实现?
  • Way to add headers to GatewayResponses in SAM template?

    • 在SAM模板中添加头部到GatewayResponses的方法是什么?

What im trying to achive:

  • 我想要实现的目标是:

Define gateway responses and integration responses inside a SAM CloudFront template.

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

What i checked so far:

  • 我目前已经检查的内容有:

SAM github link
SAM issue

I was checking SAM github but for me it wasnt clear how to do it based on the above link. Also i didnt found any answer on stackoverflow which would explain why the headers are bad in my gatewayresponse snippet

  • 我在检查SAM GitHub时,对于我来说不太清楚如何根据上面的链接来实现。而且我在Stack Overflow上也没有找到任何解释为什么我的网关响应片段中的头部有问题的答案。

Every Help is appreciated

  • 感谢任何帮助。

Some examples:

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

Expected function level integrationResponse:

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
英文:

Questions:

  • IntegrationResponse to Sam template ? Is it possible without OpenApi?
  • Way to add headers to GatewayResponses in SAM template?

What im trying to achive:

  • Define gateway responses and integration responses inside a SAM
    CloudFront template.

What i checked so far:

I was checking SAM github but for me it wasnt clear how to do it based on the above link.
Also i didnt found any answer on stackoverflow which would explain why the headers are bad in my gatewayresponse snippet

Every Help is appreciated

Some examples:

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

Expected function level integrationResponse:

  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

答案1

得分: 1

以下是翻译好的内容:

"So long story short half of my question is stupid. in proxy integration API GW is by defult returning the response from server to client no need further declaration in SAM template.

As for the headers the following way is the correct:

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"

英文:

So long story short half of my question is stupid. in proxy integration API GW is by defult returning the response from server to client no need further declaration in SAM template.

As for the headers the following way is the correct:

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

huangapple
  • 本文由 发表于 2020年1月3日 18:15:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定