微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我尝试向网关添加新路由时,AWS 云形成总是失败

如何解决当我尝试向网关添加新路由时,AWS 云形成总是失败

我现在尝试了 7 次,但仍然失败。我正在向我的 API 网关添加一个新的路由端点。我已对云形成文件进行了必要的更改并将其上传到 AWS。

每次尝试都出现以下错误,我不知道如何解决

'comp/*/*' is not a valid method path. Method paths can be defined as
{resource_path}/{http_method} for an individual method override,or */* for overriding all methods in the stage. 
(Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; 
Request ID: 0878sd34-4555-987s-3332-8dfg7d8f9;
 Proxy: null)

这是云形成文件的一部分。

      DevEnvstage:
        Type: "AWS::ApiGateway::Stage"
        Properties:
          RestApiId: !Ref RestApi
          StageName: 'dev'
          Description: Stage for development environment
          DeploymentId: !Ref FakeStageDeployment
          CacheClusterEnabled: false
          MethodSettings:
            - HttpMethod: "*"
              ResourcePath: "/red/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/yellow/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/blue/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/comp/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/dribl/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
          Variables:
            "": ""
    
      QaEnvstage:
        Type: "AWS::ApiGateway::Stage"
        Properties:
          RestApiId: !Ref RestApi
          StageName: 'qa'
          Description: Stage for development environment
          DeploymentId: !Ref FakeStageDeployment
          CacheClusterEnabled: false
          MethodSettings:
            - HttpMethod: "*"
              ResourcePath: "/black/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/red/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/yellow/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/blue/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/comp/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
          Variables:
            "": ""
    
      StageEnvstage:
        Type: "AWS::ApiGateway::Stage"
        Properties:
          RestApiId: !Ref RestApi
          StageName: 'stg'
          Description: Stage for development environment
          DeploymentId: !Ref FakeStageDeployment
          CacheClusterEnabled: false
          MethodSettings:
            - HttpMethod: "*"
              ResourcePath: "/black/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/red/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/yellow/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/blue/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/comp/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
          Variables:
            "": ""
    
      ProdEnvstage:
        Type: "AWS::ApiGateway::Stage"
        Properties:
          RestApiId: !Ref RestApi
          StageName: 'prod'
          Description: Stage for development environment
          DeploymentId: !Ref FakeStageDeployment
          CacheClusterEnabled: false
          MethodSettings:
            - HttpMethod: "*"
              ResourcePath: "/yellow/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/red/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/red/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/blue/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/comp/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
            - HttpMethod: "*"
              ResourcePath: "/*"
              CachingEnabled: true
              CacheDataEncrypted: false
              CacheTtlInSeconds: 180
          Variables:
            "Hostname": ""
    
      DevEnvGatewayCustomDomain:
        Type: "AWS::ApiGateway::DomainName"
        Properties:
          DomainName: ""
          CertificateArn: ""
          EndpointConfiguration:
            Types:
              - EDGE
    
      DevEnvGatewayBasePathMapping:
        Type: "AWS::ApiGateway::BasePathMapping"
        Properties:
          RestApiId: !Ref RestApi
          DomainName: !Ref DevEnvGatewayCustomDomain
          Stage: !Ref DevEnvstage
    
      QaEnvGatewayCustomDomain:
        Type: "AWS::ApiGateway::DomainName"
        Properties:
          DomainName: ""
          CertificateArn: ""
          EndpointConfiguration:
            Types:
              - EDGE
    
      QaEnvGatewayBasePathMapping:
        Type: "AWS::ApiGateway::BasePathMapping"
        Properties:
          RestApiId: !Ref RestApi
          DomainName: !Ref QaEnvGatewayCustomDomain
          Stage: !Ref QaEnvstage
    
      StageEnvGatewayCustomDomain:
        Type: "AWS::ApiGateway::DomainName"
        Properties:
          DomainName: ""
          CertificateArn: ""
          EndpointConfiguration:
            Types:
              - EDGE
    
      StageEnvGatewayBasePathMapping:
        Type: "AWS::ApiGateway::BasePathMapping"
        Properties:
          RestApiId: !Ref RestApi
          DomainName: !Ref StageEnvGatewayCustomDomain
          Stage: !Ref StageEnvstage
    
      ProdEnvGatewayCustomDomain:
        Type: "AWS::ApiGateway::DomainName"
        Properties:
          DomainName: ""
          CertificateArn: ""
          EndpointConfiguration:
            Types:
              - EDGE
    
      ProdEnvGatewayBasePathMapping:
        Type: "AWS::ApiGateway::BasePathMapping"
        Properties:
          RestApiId: !Ref RestApi
          DomainName: !Ref ProdEnvGatewayCustomDomain
          Stage: !Ref ProdEnvstage

正如您在方法设置部分中看到的那样。 comp 的 HttpMehod 是“/comp/*”而不是“/comp/*/*

解决方法

您的 cloudformation 模板有问题

根据文档 AWS::ApiGateway::Stage MethodSetting

  • HttpMethod

HTTP 方法。要将设置应用于多个资源和方法,请在 HttpMethod 和 ResourcePath 中指定星号 (*)。

  • 资源路径

此方法的资源路径。正斜杠 (/) 被编码为 ~1 并且初始斜杠必须包含一个正斜杠。例如,路径值 /resource/subresource 必须编码为 /~1resource~1subresource。要指定根路径,请仅使用斜杠 (/)。要将设置应用于多个资源和方法,请在 HttpMethod 和 ResourcePath 中指定星号 (*)。

,

遇到了同样的问题。添加 * 对单个端点不起作用。尝试添加您的 {resource_path} 并指定 {http_method}。为我工作。

例如:

ResourcePath: '/api/resource/{Id}'
HttpMethod: 'GET'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。