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

Hello,
I had a cors problem when trying to call a lambda function, when trying to fix the problem, I added an APIGateway as a resource like mentioned here: Your CORS and API Gateway survival guide

When I’ve deployed the serverless project, I got this error:
The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template
and couldn’t find a solution to that.
here is my serverless.yml file:


resources:
  Resources:
    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'

functions:
  relay:
    handler: "./src/functions/transfer/handler.main"
    events:
      - httpApi: "post /transfer"
      - cors: true

if someone could help me, I’ll be so grateful.

thanks

1 Like