2

在我们的无服务器应用程序中,我们将以下内容添加到 serverless.yml 的资源块中,以便 4xx 和 5xx 错误响应具有 CORS 标头。

    GatewayResponseDefault4XX:
      Type: 'AWS::ApiGateway::GatewayResponse'
      Properties:
        ResponseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
        ResponseType: DEFAULT_4XX
        RestApiId:
          Ref: 'ApiGatewayRestApi'

    GatewayResponseDefault5XX:
      Type: 'AWS::ApiGateway::GatewayResponse'
      Properties:
        ResponseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
        ResponseType: DEFAULT_5XX
        RestApiId:
          Ref: 'ApiGatewayRestApi'

直到最近这对我们有用,但现在它在尝试使用serverless deploy. 当我们部署应用程序并从我们的serverless.yml.

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayResourceViewer, ApiGatewayRestApi] in the Resources block of the template.

但问题是我们需要这些资源才能成功捕获从应用程序返回的 4xx 和 5xx 错误。我们不能只是删除这些并继续。

有什么方法可以保留这些资源并且仍然可以无错误地部署我们的应用程序?非常感谢有用的建议。

背景资料

serverless-plugin-split-stacks配置:

custom:
  splitStacks:
    perFunction: false
    perType: true
    perGroupFunction: false

serverless -v输出:

Framework Core: 2.15.0
Plugin: 4.4.2
SDK: 2.3.2
Components: 3.4.7
4

0 回答 0