amazon-web-services - 云形成 : extraneous key [DependsOn] is not permitted

标签 amazon-web-services aws-cloudformation aws-api-gateway aws-sam

使用 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

关于amazon-web-services - 云形成 : extraneous key [DependsOn] is not permitted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71114536/

相关文章:

amazon-web-services - 使用 API Gateway POST 到 SQS 时无法确定要授权的服务/操作名称

php - AWS EC2 - Amazon Linux AMI - PHP 脚本不起作用(Slim 框架)

amazon-web-services - 描述 CloudFormation 中的 AWS API Gateway 正文映射模板

amazon-web-services - 遇到不支持的属性 Indexdocument

typescript - 使用 AWS CDK 的 API 网关 GET 方法请求 URL 查询字符串参数

amazon-web-services - AWS API网关需要手动部署吗?

javascript - 在 JavaScript 中生成 Amazon API 签名,导入哈希函数 (jQuery)

amazon-web-services - 基于标签限制访问时无法访问其他角色

java - Maven 获取特定类

aws-cloudformation - StackCreate验证错误: Condition token can only be used in Conditions block