Skip to content

(apigateway): default deployOptions mistake 0 for undefined #20860

@flemjame-at-amazon

Description

@flemjame-at-amazon

Describe the bug

When creating an SpecRestApi with "0" values for the top level throttlingBurstLimit and throttlingRateLimit, they are not rendered in the CFN template unless metricsEnabled is also set to true. This causes them to be the defaults of 10000 and 5000, instead of 0.

Setting these to zero is valuable because it lets us enforce per-method throttling options. In short, if you don't supply per-method options, a method without such options can't be called.

Expected Behavior

 "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "MethodSettings": [
     {
      "DataTraceEnabled": false,
      "HttpMethod": "*",
      "ResourcePath": "/*",
      "ThrottlingBurstLimit": 0,
      "ThrottlingRateLimit": 0
     }
    ],
    "StageName": "prod"
   }
  },

Current Behavior

  "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "StageName": "prod"
   }
  },

Reproduction Steps

The failing case:

new SpecRestApi(newStack, 'test-api', {
  apiDefinition: ApiDefinition.fromInline({
    openapi: '3.0.2'
  }),
  deployOptions: { // If these values are provided, none of the three are rendered
    throttlingBurstLimit: 0,
    throttlingRateLimit: 0,
    metricsEnabled: false
  }
})

  "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "StageName": "prod"
   }
  },

Example cases that I think demonstrates that it's a falsey value problem where zero is interpreted wrongly

new SpecRestApi(newStack, 'test-api', {
  apiDefinition: ApiDefinition.fromInline({
    openapi: '3.0.2'
  }),
  deployOptions: {
    throttlingBurstLimit: 0,
    throttlingRateLimit: 0,
    metricsEnabled: true  // With this one set to true, all three fields are rendered
  }
})

 "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "MethodSettings": [
     {
      "DataTraceEnabled": false,
      "HttpMethod": "*",
      "MetricsEnabled": true,
      "ResourcePath": "/*",
      "ThrottlingBurstLimit": 0,
      "ThrottlingRateLimit": 0
     }
    ],
    "StageName": "prod"
   }
  },

new SpecRestApi(stack, 'test-api', {
  apiDefinition: ApiDefinition.fromInline({
    openapi: '3.0.2'
  }),
  deployOptions: {
    throttlingBurstLimit: undefined,
    throttlingRateLimit: undefined,
    metricsEnabled: false
  }
})


  "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "StageName": "prod"
   }
  },
new SpecRestApi(newStack, 'test-api', {
  apiDefinition: ApiDefinition.fromInline({
    openapi: '3.0.2'
  }),
  deployOptions: {
    throttlingBurstLimit: undefined,
    throttlingRateLimit: undefined,
    metricsEnabled: true
  }
})

 "testapiDeploymentStageprod5C9E92A4": {
   "Type": "AWS::ApiGateway::Stage",
   "Properties": {
    "RestApiId": {
     "Ref": "testapiD6451F70"
    },
    "DeploymentId": {
     "Ref": "testapiDeployment356D2C3575dab415a1b5df33a3aac5d75777556a"
    },
    "MethodSettings": [
     {
      "DataTraceEnabled": false,
      "HttpMethod": "*",
      "MetricsEnabled": true,
      "ResourcePath": "/*"
     }
    ],
    "StageName": "prod"
   }
  },


### Possible Solution

I think one or more of the deployOptions values are being interpreted incorrectly as falsey. 

### Additional Information/Context

_No response_

### CDK CLI Version

1.160.0

### Framework Version

_No response_

### Node.js Version

14

### OS

OSX

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-apigatewayRelated to Amazon API GatewaybugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions