aws-cdk-lib.aws_apigateway.UsagePlan

class UsagePlan (construct)

LanguageType name
.NETAmazon.CDK.AWS.APIGateway.UsagePlan
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#UsagePlan
Javasoftware.amazon.awscdk.services.apigateway.UsagePlan
Pythonaws_cdk.aws_apigateway.UsagePlan
TypeScript (source)aws-cdk-lib » aws_apigateway » UsagePlan

Implements IConstruct, IDependable, IResource, IUsagePlan

Example

declare const integration: apigateway.LambdaIntegration;

const api = new apigateway.RestApi(this, 'hello-api');

const v1 = api.root.addResource('v1');
const echo = v1.addResource('echo');
const echoMethod = echo.addMethod('GET', integration, { apiKeyRequired: true });

const plan = api.addUsagePlan('UsagePlan', {
  name: 'Easy',
  throttle: {
    rateLimit: 10,
    burstLimit: 2
  }
});

const key = api.addApiKey('ApiKey');
plan.addApiKey(key);

Initializer

new UsagePlan(scope: Construct, id: string, props?: UsagePlanProps)

Parameters

  • scope Construct
  • id string
  • props UsagePlanProps

Construct Props

NameTypeDescription
apiStages?UsagePlanPerApiStage[]API Stages to be associated with the usage plan.
description?stringRepresents usage plan purpose.
name?stringName for this usage plan.
quota?QuotaSettingsNumber of requests clients can make in a given time period.
throttle?ThrottleSettingsOverall throttle settings for the API.

apiStages?

Type: UsagePlanPerApiStage[] (optional, default: none)

API Stages to be associated with the usage plan.


description?

Type: string (optional, default: none)

Represents usage plan purpose.


name?

Type: string (optional, default: none)

Name for this usage plan.


quota?

Type: QuotaSettings (optional, default: none)

Number of requests clients can make in a given time period.


throttle?

Type: ThrottleSettings (optional, default: none)

Overall throttle settings for the API.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
usagePlanIdstringId of the usage plan.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


usagePlanId

Type: string

Id of the usage plan.

Methods

NameDescription
addApiKey(apiKey, options?)Adds an ApiKey.
addApiStage(apiStage)Adds an apiStage.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.
static fromUsagePlanId(scope, id, usagePlanId)Import an externally defined usage plan using its ARN.

addApiKey(apiKey, options?)

public addApiKey(apiKey: IApiKey, options?: AddApiKeyOptions): void

Parameters

  • apiKey IApiKey — the api key to associate with this usage plan.
  • options AddApiKeyOptions — options that control the behaviour of this method.

Adds an ApiKey.


addApiStage(apiStage)

public addApiStage(apiStage: UsagePlanPerApiStage): void

Parameters

  • apiStage UsagePlanPerApiStage

Adds an apiStage.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromUsagePlanId(scope, id, usagePlanId)

public static fromUsagePlanId(scope: Construct, id: string, usagePlanId: string): IUsagePlan

Parameters

  • scope Construct — the construct that will "own" the imported usage plan.
  • id string — the id of the imported usage plan in the construct tree.
  • usagePlanId string — the id of an existing usage plan.

Returns

  • IUsagePlan

Import an externally defined usage plan using its ARN.