UNPKG

5.28 kBTypeScriptView Raw
1import { IResource, Resource } from '@aws-cdk/core';
2import { Construct } from 'constructs';
3import { IApiKey } from './api-key';
4import { Method } from './method';
5import { IRestApi } from './restapi';
6import { Stage } from './stage';
7/**
8 * Container for defining throttling parameters to API stages or methods.
9 * @link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-throttling.html
10 */
11export interface ThrottleSettings {
12 /**
13 * The API request steady-state rate limit (average requests per second over an extended period of time)
14 * @default none
15 */
16 readonly rateLimit?: number;
17 /**
18 * The maximum API request rate limit over a time ranging from one to a few seconds.
19 * @default none
20 */
21 readonly burstLimit?: number;
22}
23/**
24 * Time period for which quota settings apply.
25 */
26export declare enum Period {
27 DAY = "DAY",
28 WEEK = "WEEK",
29 MONTH = "MONTH"
30}
31/**
32 * Specifies the maximum number of requests that clients can make to API Gateway APIs.
33 */
34export interface QuotaSettings {
35 /**
36 * The maximum number of requests that users can make within the specified time period.
37 * @default none
38 */
39 readonly limit?: number;
40 /**
41 * For the initial time period, the number of requests to subtract from the specified limit.
42 * @default none
43 */
44 readonly offset?: number;
45 /**
46 * The time period for which the maximum limit of requests applies.
47 * @default none
48 */
49 readonly period?: Period;
50}
51/**
52 * Represents per-method throttling for a resource.
53 */
54export interface ThrottlingPerMethod {
55 /**
56 * [disable-awslint:ref-via-interface]
57 * The method for which you specify the throttling settings.
58 * @default none
59 */
60 readonly method: Method;
61 /**
62 * Specifies the overall request rate (average requests per second) and burst capacity.
63 * @default none
64 */
65 readonly throttle: ThrottleSettings;
66}
67/**
68 * Represents the API stages that a usage plan applies to.
69 */
70export interface UsagePlanPerApiStage {
71 /**
72 * @default none
73 */
74 readonly api?: IRestApi;
75 /**
76 *
77 * [disable-awslint:ref-via-interface]
78 * @default none
79 */
80 readonly stage?: Stage;
81 /**
82 * @default none
83 */
84 readonly throttle?: ThrottlingPerMethod[];
85}
86export interface UsagePlanProps {
87 /**
88 * API Stages to be associated with the usage plan.
89 * @default none
90 */
91 readonly apiStages?: UsagePlanPerApiStage[];
92 /**
93 * Represents usage plan purpose.
94 * @default none
95 */
96 readonly description?: string;
97 /**
98 * Number of requests clients can make in a given time period.
99 * @default none
100 */
101 readonly quota?: QuotaSettings;
102 /**
103 * Overall throttle settings for the API.
104 * @default none
105 */
106 readonly throttle?: ThrottleSettings;
107 /**
108 * Name for this usage plan.
109 * @default none
110 */
111 readonly name?: string;
112 /**
113 * ApiKey to be associated with the usage plan.
114 * @default none
115 * @deprecated use `addApiKey()`
116 */
117 readonly apiKey?: IApiKey;
118}
119/**
120 * Options to the UsagePlan.addApiKey() method
121 */
122export interface AddApiKeyOptions {
123 /**
124 * Override the CloudFormation logical id of the AWS::ApiGateway::UsagePlanKey resource
125 * @default - autogenerated by the CDK
126 */
127 readonly overrideLogicalId?: string;
128}
129/**
130 * A UsagePlan, either managed by this CDK app, or imported.
131 */
132export interface IUsagePlan extends IResource {
133 /**
134 * Id of the usage plan
135 * @attribute
136 */
137 readonly usagePlanId: string;
138 /**
139 * Adds an ApiKey.
140 *
141 * @param apiKey the api key to associate with this usage plan
142 * @param options options that control the behaviour of this method
143 */
144 addApiKey(apiKey: IApiKey, options?: AddApiKeyOptions): void;
145}
146declare abstract class UsagePlanBase extends Resource implements IUsagePlan {
147 /**
148 * Id of the usage plan
149 * @attribute
150 */
151 abstract readonly usagePlanId: string;
152 /**
153 * Adds an ApiKey.
154 *
155 * @param apiKey the api key to associate with this usage plan
156 * @param options options that control the behaviour of this method
157 */
158 addApiKey(apiKey: IApiKey, options?: AddApiKeyOptions): void;
159}
160export declare class UsagePlan extends UsagePlanBase {
161 /**
162 * Import an externally defined usage plan using its ARN.
163 *
164 * @param scope the construct that will "own" the imported usage plan.
165 * @param id the id of the imported usage plan in the construct tree.
166 * @param usagePlanId the id of an existing usage plan.
167 */
168 static fromUsagePlanId(scope: Construct, id: string, usagePlanId: string): IUsagePlan;
169 /**
170 * @attribute
171 */
172 readonly usagePlanId: string;
173 private readonly apiStages;
174 constructor(scope: Construct, id: string, props?: UsagePlanProps);
175 /**
176 * Adds an apiStage.
177 * @param apiStage
178 */
179 addApiStage(apiStage: UsagePlanPerApiStage): void;
180 /**
181 *
182 * @param props
183 */
184 private renderApiStages;
185 private createStage;
186 private renderQuota;
187 private renderThrottle;
188 private renderThrottlePerMethod;
189}
190export {};