mana
mana

Reputation: 1239

AWS Cloud formation always failed when I try to add new route to gateway

I tried 7 times now but still failed. I'm adding a new route endpoint to my API gateway. I've made the required changes on the cloud formation file and upload it to AWS.

Every try, I got the following error, I don't know how to fix it.

'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)

Here's a part of the cloud formation file.

      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

As you can see in the method settings section. The HttpMehod for comp is "/comp/*" not "/comp/*/*"

Upvotes: 4

Views: 1573

Answers (1)

sachin roy
sachin roy

Reputation: 52

Had the same problem. Adding * didn't work for individual endpoints. Try adding your {resource_path} and specify the {http_method}. Worked for me.

eg:

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

Upvotes: 0

Related Questions