Skip to content

Resource: awsApiGatewayUsagePlan

Provides an API Gateway Usage Plan.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsApiGatewayRestApiExample = new aws.apiGatewayRestApi.ApiGatewayRestApi(
  this,
  "example",
  {
    body: '${jsonencode({\n    openapi = "3.0.1"\n    info = {\n      title   = "example"\n      version = "1.0"\n    }\n    paths = {\n      "/path1" = {\n        get = {\n          x-amazon-apigateway-integration = {\n            httpMethod           = "GET"\n            payloadFormatVersion = "1.0"\n            type                 = "HTTP_PROXY"\n            uri                  = "https://ip-ranges.amazonaws.com/ip-ranges.json"\n          }\n        }\n      }\n    }\n  })}',
    name: "example",
  }
);
const awsApiGatewayDeploymentExample =
  new aws.apiGatewayDeployment.ApiGatewayDeployment(this, "example_1", {
    restApiId: awsApiGatewayRestApiExample.id,
    triggers: {
      redeployment: `\${sha1(jsonencode(${awsApiGatewayRestApiExample.body}))}`,
    },
  });
awsApiGatewayDeploymentExample.addOverride("lifecycle", [
  {
    create_before_destroy: true,
  },
]);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayDeploymentExample.overrideLogicalId("example");
const awsApiGatewayStageDevelopment = new aws.apiGatewayStage.ApiGatewayStage(
  this,
  "development",
  {
    deploymentId: awsApiGatewayDeploymentExample.id,
    restApiId: awsApiGatewayRestApiExample.id,
    stageName: "development",
  }
);
const awsApiGatewayStageProduction = new aws.apiGatewayStage.ApiGatewayStage(
  this,
  "production",
  {
    deploymentId: awsApiGatewayDeploymentExample.id,
    restApiId: awsApiGatewayRestApiExample.id,
    stageName: "production",
  }
);
const awsApiGatewayUsagePlanExample =
  new aws.apiGatewayUsagePlan.ApiGatewayUsagePlan(this, "example_4", {
    apiStages: [
      {
        apiId: awsApiGatewayRestApiExample.id,
        stage: awsApiGatewayStageDevelopment.stageName,
      },
      {
        apiId: awsApiGatewayRestApiExample.id,
        stage: awsApiGatewayStageProduction.stageName,
      },
    ],
    description: "my description",
    name: "my-usage-plan",
    productCode: "MYCODE",
    quotaSettings: {
      limit: 20,
      offset: 2,
      period: "WEEK",
    },
    throttleSettings: {
      burstLimit: 5,
      rateLimit: 10,
    },
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayUsagePlanExample.overrideLogicalId("example");

Argument Reference

The API Gateway Usage Plan argument layout is a structure composed of several sub-resources - these resources are laid out below.

Top-Level Arguments

  • name - (Required) Name of the usage plan.
  • description - (Optional) Description of a usage plan.
  • apiStages - (Optional) Associated API stages of the usage plan.
  • quotaSettings - (Optional) The quota settings of the usage plan.
  • throttleSettings - (Optional) The throttling limits of the usage plan.
  • productCode - (Optional) AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
  • tags - (Optional) Key-value map of resource tags. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Api Stages arguments

  • apiId (Required) - API Id of the associated API stage in a usage plan.
  • stage (Required) - API stage name of the associated API stage in a usage plan.
  • throttle - (Optional) The throttling limits of the usage plan.
Throttle
  • path (Required) - Method to apply the throttle settings for. Specfiy the path and method, for example /test/get.
  • burstLimit (Optional) - The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
  • rateLimit (Optional) - The API request steady-state rate limit.

Quota Settings Arguments

  • limit (Optional) - Maximum number of requests that can be made in a given time period.
  • offset (Optional) - Number of requests subtracted from the given limit in the initial time period.
  • period (Optional) - Time period in which the limit applies. Valid values are "DAY", "WEEK" or "MONTH".

Throttling Settings Arguments

  • burstLimit (Optional) - The API request burst limit, the maximum rate limit over a time ranging from one to a few seconds, depending upon whether the underlying token bucket is at its full capacity.
  • rateLimit (Optional) - The API request steady-state rate limit.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - ID of the API resource
  • name - Name of the usage plan.
  • description - Description of a usage plan.
  • apiStages - Associated API stages of the usage plan.
  • quotaSettings - Quota of the usage plan.
  • throttleSettings - Throttling limits of the usage plan.
  • productCode - AWS Marketplace product identifier to associate with the usage plan as a SaaS product on AWS Marketplace.
  • arn - ARN
  • tagsAll - Map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

AWS API Gateway Usage Plan can be imported using the id, e.g.,

$ terraform import aws_api_gateway_usage_plan.myusageplan <usage_plan_id>