skip to Main Content

In below API usage cft I unable to parameterize the api resource and meythod.

ApiUsagePlan:
    Type: "AWS::ApiGateway::UsagePlan"
    Properties:
      Throttle:
        RateLimit: 1000
        BurstLimit: 5000
      ApiStages:
      - ApiId: !Ref MyApiGatewayApi
        Stage: !Ref MyApiStage
        Throttle:
         "/hello/world/GET": <--- How to get this parameterised
          RateLimit: 50
          BurstLimit: 50

I am getting below error instead

esource handler returned message: "Invalid patch path '/apiStages/sk4knm4yub:ppe-auth/throttle/!Ref MethodName/burstLimit' specified for op 'replace'. Must be one of: 
[/name, /description, /productCode, /quota/period, /quota/limit, /quota/offset, /throttle/rateLimit, /throttle/burstLimit, /apiStages/<apidId:stageName>/throttle/<resourcePath>/<httpMethod>/rateLimit, /apiStages/<apidId:stageName>/throttle/<resourcePath>/<httpMethod>/burstLimit, /apiStages/<apidId:stageName>/throttle] (Service: ApiGateway, Status Code: 400, Request ID: 5ff7c212-bb69-4284-9a4b-6fa2305d5945)" (RequestToken: 7ae87cae-198e-01d7-ef3e-afdfa2a6472b, HandlerErrorCode: InvalidRequest)

expecting to apply the input parameter for resource and method

2

Answers


  1. How to get this parameterised

    Its not possible with CloudFormation. You would have to developed per-processing procedure of the template before uploading or using some macro or a custom resource.

    Login or Signup to reply.
  2. The error occurs because CloudFormation does not support directly parameterizing API Gateway resource paths (/hello/world) and HTTP methods (GET) inside the Throttle configuration. But, you can use the !Sub function to dynamically construct the path based on parameters.

    This is an example:

    Parameters:
      ApiResourcePath:
        Type: String
        Default: "/hello/world"  
        Description: "The API resource path for throttling"
      HttpMethod:
        Type: String
        Default: "GET"
        Description: "The HTTP method for the API resource"
    
    Resources:
      ApiUsagePlan:
        Type: "AWS::ApiGateway::UsagePlan"
        Properties:
          Throttle:
            RateLimit: 1000
            BurstLimit: 5000
          ApiStages:
            - ApiId: !Ref MyApiGatewayApi
              Stage: !Ref MyApiStage
              Throttle:
                !Sub 
                  - "${ApiResourcePath}/${HttpMethod}"
                  - {
                      ApiResourcePath: !Ref ApiResourcePath,
                      HttpMethod: !Ref HttpMethod
                    }:
                    RateLimit: 50
                    BurstLimit: 50
    

    Now with this approach we can the Throttle key dynamically resolves to something like "/hello/world/GET" during stack creation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search