Template format error: Unresolved resource dependencies occurs when response resources are added for 4xx and 5xx errors

Viewed 760

In our serverless app, we have added the following to the resources block of serverless.yml so that 4xx and 5xx error responses have CORS headers.

    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'

This worked for us until recently, but now It causes the following error when trying to deploy the app using serverless deploy. This error goes away when we deploy the app, removing the above resources from our serverless.yml.

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

But the problem is these resources are required for us to successfully catch 4xx and 5xx errors returning from the app. We can't just remove those and proceed.

Is there any way to keep these resources and still deploy our app without errors? Helpful suggestions are highly appreciated.

Background information

serverless-plugin-split-stacks configuration:

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

serverless -v output:

Framework Core: 2.15.0
Plugin: 4.4.2
SDK: 2.3.2
Components: 3.4.7
0 Answers
Related