CloudFormation:不允许使用无关键 [DependsOn]

CloudFormation: extraneous key [DependsOn] is not permitted

使用 SAM(API 网关 + Lambda)构建一个简单的 Hello World API。有人告诉我 DependsOn 应该使用所有资源。

API配置为:

HelloWorldAPI:
    Type: AWS::Serverless::Api
    # Type: AWS::ApiGateway::RestApi
    Properties: 
      Name: HelloWorldApi
      StageName: !Ref StageName

  HelloWorldAPIResource:
    Type: AWS::ApiGateway::Resource
    Properties:
      RestApiId: !Ref HelloWorldAPI
      ParentId: !GetAtt HelloWorldAPI.RootResourceId
      PathPart: hello

  HelloWorldAPIMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      AuthorizationType: NONE
      HttpMethod: GET
      ResourceId: !Ref HelloWorldAPIResource
      RestApiId: !Ref HelloWorldAPI
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: GET
        Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorldFunction.Arn}/invocations
          # - Arn: !GetAtt HelloWorldFunction.Arn

  HelloWorldAPIDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref HelloWorldAPI
      StageName: !Ref StageName
      DependsOn:
        - HelloWorldAPIMethod

但是我在部署过程中遇到以下错误:

CREATE_FAILED                                   AWS::ApiGateway::Deployment                     HelloWorldAPIDeployment                         Properties validation failed for resource     
                                                                                                                                                HelloWorldAPIDeployment with message: #:      
                                                                                                                                                extraneous key [DependsOn] is not permitted   
CREATE_FAILED                                   AWS::ApiGateway::Resource                       HelloWorldAPIResource                           Resource creation cancelled                   
CREATE_FAILED                                   AWS::ApiGateway::Deployment                     HelloWorldAPIDeployment5332c373d4               Resource handler returned message: "The REST  
                                                                                                                                                API doesn't contain any methods (Service:     
                                                                                                                                                ApiGateway, Status Code: 400, Request ID:     
                                                                                                                                                634b4de5-ead7-48f5-8075-ab55d7176189,         
                                                                                                                                                Extended Request ID: null)" (RequestToken:    
                                                                                                                                                ef65a5fd-cdf4-fe14-2010-a513bca36aca,         
                                                                                                                                                HandlerErrorCode: InvalidRequest)             

显式定义的 AWS::ApiGateway::Deployment 无法使用 DependsOn,而另一个 AWS::ApiGateway::Deployment 正在隐式但不必要地创建,它在方法之前部署,这就是我的原因首先明确定义了一个。

感谢任何帮助。

DependsOn 应该少最后一个标签:


  HelloWorldAPIDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref HelloWorldAPI
      StageName: !Ref StageName
    DependsOn:
      - HelloWorldAPIMethod