class UsagePlan (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.APIGateway.UsagePlan |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#UsagePlan |
Java | software.amazon.awscdk.services.apigateway.UsagePlan |
Python | aws_cdk.aws_apigateway.UsagePlan |
TypeScript (source) | aws-cdk-lib » aws_apigateway » UsagePlan |
Implements
IConstruct
, IDependable
, IResource
, IUsage
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
Usage
Plan Props
Construct Props
Name | Type | Description |
---|---|---|
api | Usage [] | API Stages to be associated with the usage plan. |
description? | string | Represents usage plan purpose. |
name? | string | Name for this usage plan. |
quota? | Quota | Number of requests clients can make in a given time period. |
throttle? | Throttle | Overall throttle settings for the API. |
apiStages?
Type:
Usage
[]
(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:
Quota
(optional, default: none)
Number of requests clients can make in a given time period.
throttle?
Type:
Throttle
(optional, default: none)
Overall throttle settings for the API.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
usage | string | Id of the usage plan. |
env
Type:
Resource
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
Name | Description |
---|---|
add | Adds an ApiKey. |
add | Adds an apiStage. |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Import an externally defined usage plan using its ARN. |
ApiKey(apiKey, options?)
addpublic addApiKey(apiKey: IApiKey, options?: AddApiKeyOptions): void
Parameters
- apiKey
IApi
— the api key to associate with this usage plan.Key - options
Add
— options that control the behaviour of this method.Api Key Options
Adds an ApiKey.
ApiStage(apiStage)
addpublic addApiStage(apiStage: UsagePlanPerApiStage): void
Parameters
- apiStage
Usage
Plan Per Api Stage
Adds an apiStage.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
UsagePlanId(scope, id, usagePlanId)
static frompublic 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
Import an externally defined usage plan using its ARN.