You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Serverless部署报错:模板Resources块存在未解析的资源依赖

Answer

This error almost always happens because your API Gateway models aren't properly nested under the provider.apiGateway.models section in your serverless.yml. Serverless needs this explicit configuration to generate the corresponding CloudFormation resources (like ErrorResponseModel) that your function's documentation references.

Step-by-Step Fixes:

  1. Move models to the correct configuration block
    Update your serverless.yml to wrap all model definitions under provider.apiGateway.models. Here's how that should look:

    provider:
      name: aws
      runtime: nodejs18.x # Replace with your actual runtime
      apiGateway:
        models:
          - name: "Player"
            description: "Golf Player"
            contentType: "application/json"
            schema:
              type: object
              properties:
                FirstName:
                  type: string
                  description: "Player First Name"
                LastName:
                  type: string
                  description: "Player Last Name"
          - name: "Booking"
            contentType: "application/json"
            schema:
              type: object
              properties:
                _id:
                  type: string
                  description: "Booking ObjectId"
                slotId:
                  type: string
                  description: "timeslot ID"
                startTime:
                  type: string
                  description: "Booking Start Time"
                endTime:
                  type: string
                  description: "Booking End Time"
                accountId:
                  type: string
                  description: "Booker Account ID"
                Players:
                  type: array
                  items:
                    $ref: "{{model: Player}}"
          - name: "ErrorResponse"
            contentType: "application/json"
            schema:
              type: object
              properties:
                message:
                  type: string
                statusCode:
                  type: number
    
  2. Verify model name consistency
    Double-check that the model names you reference in methodResponses.responseModels (e.g., ErrorResponse, Booking) match exactly with the name values in your model definitions (case-sensitive). Your current configuration looks correct here, but typos are easy to miss!

  3. Update Serverless Framework (if needed)
    Older versions of the Serverless Framework had bugs with API Gateway model handling. Update to the latest stable version to rule this out:

    npm install -g serverless
    
  4. Clean and redeploy
    Sometimes residual CloudFormation stack artifacts cause issues. Clean up the existing stack and redeploy fresh:

    serverless remove
    serverless deploy
    

Why This Works:

When you define models outside of provider.apiGateway.models, Serverless doesn't generate the necessary AWS::ApiGateway::Model resources in the CloudFormation template. But your function's documentation still references these models, leaving CloudFormation unable to find the required resources—hence the "unresolved dependency" error. By moving the models to the correct section, Serverless will automatically create the matching CloudFormation resources, resolving the dependency.


内容的提问来源于stack exchange,提问作者ROKIKOKI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:50:35