Home > Enterprise >  CloudFormation: extraneous key [DependsOn] is not permitted
CloudFormation: extraneous key [DependsOn] is not permitted

Time:02-15

Building a simple Hello World API using SAM(API Gateway Lambda). I was told DependsOn is supposed to work with all resources.

The APIs were configured as :

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

But I get the following errors during deployment:

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)             

The explicitly defined AWS::ApiGateway::Deployment is unable to use DependsOn, while there is another AWS::ApiGateway::Deployment being created implicitly but unnecessarily which is being deployed before the method, which was the reason I defined one explicitly in the first place.

Any help is appreciated.

CodePudding user response:

DependsOn should have one last tab less:


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

  • Related