@ashishpandeyone/cdk-lambda-web-function 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +1520 -130
- package/.jsii.tabl.json +1 -1
- package/API.md +1612 -124
- package/README.md +151 -7
- package/assets/web-function-deployment/index.js +58 -0
- package/assets/web-function-provider/index.js +26 -26
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/nodejs-web-function.js +1 -1
- package/lib/private/metrics.d.ts +23 -0
- package/lib/private/metrics.js +49 -0
- package/lib/private/provider-protocol.d.ts +57 -0
- package/lib/private/provider-protocol.js +13 -2
- package/lib/private/provider.d.ts +3 -3
- package/lib/private/provider.js +16 -6
- package/lib/private/regional-alarm.d.ts +23 -0
- package/lib/private/regional-alarm.js +40 -0
- package/lib/private/revision-cleanup.d.ts +19 -0
- package/lib/private/revision-cleanup.js +38 -0
- package/lib/private/rollback.d.ts +9 -0
- package/lib/private/rollback.js +3 -0
- package/lib/private/traffic-shift.d.ts +22 -0
- package/lib/private/traffic-shift.js +144 -0
- package/lib/web-function-deployment.d.ts +153 -0
- package/lib/web-function-deployment.js +125 -0
- package/lib/web-function-endpoint.d.ts +168 -19
- package/lib/web-function-endpoint.js +292 -18
- package/lib/web-function-grants.d.ts +2 -2
- package/lib/web-function-grants.js +4 -4
- package/lib/web-function-revision.d.ts +45 -0
- package/lib/web-function-revision.js +40 -0
- package/lib/web-function.d.ts +69 -9
- package/lib/web-function.js +130 -26
- package/package.json +5 -2
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
|
|
2
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
1
3
|
import { Construct } from 'constructs';
|
|
2
4
|
import { WebFunctionAuthType, WebFunctionEndpointType } from './enums';
|
|
5
|
+
import type { IWebFunction } from './web-function';
|
|
6
|
+
import type { WebFunctionDeployment } from './web-function-deployment';
|
|
7
|
+
import { WebFunctionGrants } from './web-function-grants';
|
|
8
|
+
import type { IWebFunctionRevision } from './web-function-revision';
|
|
9
|
+
/**
|
|
10
|
+
* A revision and the share of an endpoint's traffic it receives.
|
|
11
|
+
*/
|
|
12
|
+
export interface WebFunctionRevisionWeight {
|
|
13
|
+
/** The revision. */
|
|
14
|
+
readonly revision: IWebFunctionRevision;
|
|
15
|
+
/**
|
|
16
|
+
* The revision's share of the endpoint's traffic, as a fraction (like `lambda.Alias` `additionalVersions`).
|
|
17
|
+
* Must be a whole percentage from 0.01 to 0.99.
|
|
18
|
+
*/
|
|
19
|
+
readonly weight: number;
|
|
20
|
+
}
|
|
3
21
|
/**
|
|
4
22
|
* Options for a Web Function's endpoint.
|
|
5
23
|
*/
|
|
@@ -21,37 +39,95 @@ export interface WebFunctionEndpointOptions {
|
|
|
21
39
|
readonly regions?: string[];
|
|
22
40
|
/**
|
|
23
41
|
* The endpoint's name, shown in logs (`endpointName`) and in the `lambda-web-endpoint-name` header.
|
|
42
|
+
* Names are unique per function.
|
|
24
43
|
*
|
|
25
|
-
* When omitted, the name
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
44
|
+
* When omitted, the name ends in a hash of the endpoint type and regions, so changing either deploys
|
|
45
|
+
* a new endpoint cleanly. When set, changing the endpoint type or regions also requires a new name:
|
|
46
|
+
* two endpoints of one function can't share a name, and CloudFormation creates the replacement
|
|
47
|
+
* before deleting the old one.
|
|
29
48
|
*
|
|
30
|
-
* @default - `default-<hash
|
|
49
|
+
* @default - `default-<hash>` for the function's default endpoint, `<id>-<hash>` for endpoints added with `addEndpoint`
|
|
31
50
|
*/
|
|
32
51
|
readonly endpointName?: string;
|
|
52
|
+
/**
|
|
53
|
+
* A description of the endpoint.
|
|
54
|
+
*
|
|
55
|
+
* @default - no description
|
|
56
|
+
*/
|
|
57
|
+
readonly description?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The most requests per second the endpoint accepts; excess requests get HTTP 429.
|
|
60
|
+
* Allowed: 0 (blocks all traffic), 100–1,000 in steps of 100, or 2,000–10,000 in steps of 1,000.
|
|
61
|
+
*
|
|
62
|
+
* Enforced separately in each region the endpoint serves from, so a multi-region endpoint
|
|
63
|
+
* can accept this many requests per second in every region.
|
|
64
|
+
*
|
|
65
|
+
* @default - no limit beyond the service quota of 10,000 requests per second per endpoint (per region)
|
|
66
|
+
*/
|
|
67
|
+
readonly rateLimit?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The most execution environments the endpoint may use (2–10,000). Each one uses 2 vCPUs of the account's quota.
|
|
70
|
+
*
|
|
71
|
+
* Enforced separately in each region the endpoint serves from.
|
|
72
|
+
*
|
|
73
|
+
* @default - scales within the account's vCPU quota
|
|
74
|
+
*/
|
|
75
|
+
readonly maxEnvironments?: number;
|
|
76
|
+
/**
|
|
77
|
+
* How the endpoint moves its traffic to a new revision: all at once, or in steps
|
|
78
|
+
* (`WebFunctionDeployment.canary()` or `linear()`) that watch CloudWatch alarms and move
|
|
79
|
+
* the traffic back when one goes into ALARM.
|
|
80
|
+
*
|
|
81
|
+
* A deployment in steps can't be combined with `revision`, `additionalRevisions` or `routeTraffic()`.
|
|
82
|
+
*
|
|
83
|
+
* @default WebFunctionDeployment.allAtOnce()
|
|
84
|
+
*/
|
|
85
|
+
readonly deployment?: WebFunctionDeployment;
|
|
33
86
|
}
|
|
34
87
|
/**
|
|
35
|
-
*
|
|
88
|
+
* Options for `WebFunction.addEndpoint`.
|
|
36
89
|
*/
|
|
37
|
-
interface
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
readonly functionArn: string;
|
|
42
|
-
/** ID of the revision the endpoint serves. */
|
|
43
|
-
readonly revisionId: string;
|
|
44
|
-
/** How callers are authenticated. */
|
|
90
|
+
export interface AddWebFunctionEndpointOptions extends WebFunctionEndpointOptions {
|
|
91
|
+
/**
|
|
92
|
+
* How callers of this endpoint are authenticated.
|
|
93
|
+
*/
|
|
45
94
|
readonly authType: WebFunctionAuthType;
|
|
95
|
+
/**
|
|
96
|
+
* The revision the endpoint serves, e.g. an earlier one from `WebFunctionRevision.fromRevisionAttributes`
|
|
97
|
+
* to keep this endpoint on it while others move on. Same as calling `routeTraffic`.
|
|
98
|
+
*
|
|
99
|
+
* @default - the function's current revision (`currentRevision`)
|
|
100
|
+
*/
|
|
101
|
+
readonly revision?: IWebFunctionRevision;
|
|
102
|
+
/**
|
|
103
|
+
* A second revision and its share of the endpoint's traffic; `revision` gets the rest.
|
|
104
|
+
* An endpoint routes to at most two revisions.
|
|
105
|
+
*
|
|
106
|
+
* @default - all traffic goes to `revision`
|
|
107
|
+
*/
|
|
108
|
+
readonly additionalRevisions?: WebFunctionRevisionWeight[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Internal: how `WebFunction` creates its endpoints. Not part of the public API.
|
|
112
|
+
*/
|
|
113
|
+
interface WebFunctionEndpointProps extends AddWebFunctionEndpointOptions {
|
|
114
|
+
/** The function that owns the endpoint. */
|
|
115
|
+
readonly webFunction: IWebFunction;
|
|
116
|
+
/** The function's current revision, served unless `revision` is given. */
|
|
117
|
+
readonly currentRevision: IWebFunctionRevision;
|
|
118
|
+
/** Prefix of the generated endpoint name. */
|
|
119
|
+
readonly namePrefix: string;
|
|
120
|
+
/** Extra input to the generated name's hash (the construct ID of an added endpoint). */
|
|
121
|
+
readonly nameSeed?: string;
|
|
46
122
|
}
|
|
47
123
|
/**
|
|
48
|
-
*
|
|
124
|
+
* An HTTPS endpoint of a Web Function: `fn.endpoint` (the default one) or the result of `fn.addEndpoint()`.
|
|
49
125
|
*
|
|
50
|
-
*
|
|
126
|
+
* Endpoints are created only through `WebFunction`, which owns their log groups in every region, so the constructor is private.
|
|
51
127
|
*/
|
|
52
128
|
export declare class WebFunctionEndpoint extends Construct {
|
|
53
129
|
/**
|
|
54
|
-
* Creates
|
|
130
|
+
* Creates an endpoint of a Web Function. Used by `WebFunction`.
|
|
55
131
|
*
|
|
56
132
|
* @internal
|
|
57
133
|
*/
|
|
@@ -62,6 +138,8 @@ export declare class WebFunctionEndpoint extends Construct {
|
|
|
62
138
|
readonly endpointArn: string;
|
|
63
139
|
/** Where the endpoint serves traffic from. */
|
|
64
140
|
readonly endpointType: WebFunctionEndpointType;
|
|
141
|
+
/** How callers of the endpoint are authenticated. */
|
|
142
|
+
readonly authType: WebFunctionAuthType;
|
|
65
143
|
/** Every region the endpoint serves from: the home region first, then the others in alphabetical order. */
|
|
66
144
|
readonly regions: string[];
|
|
67
145
|
/**
|
|
@@ -72,9 +150,19 @@ export declare class WebFunctionEndpoint extends Construct {
|
|
|
72
150
|
* The endpoint's URL: the global URL for `MULTI_REGION`, otherwise the home region's.
|
|
73
151
|
*/
|
|
74
152
|
readonly url: string;
|
|
153
|
+
/** Grants on this endpoint (e.g. `grants.invoke(principal)`). */
|
|
154
|
+
readonly grants: WebFunctionGrants;
|
|
155
|
+
/**
|
|
156
|
+
* The alarms this endpoint created for its deployment's `rollbackOn`, one per threshold in every region it serves from
|
|
157
|
+
* (the home region's first). Empty without `rollbackOn`.
|
|
158
|
+
*/
|
|
159
|
+
readonly rollbackAlarms: cloudwatch.IAlarm[];
|
|
75
160
|
private readonly homeRegion;
|
|
76
|
-
private readonly
|
|
77
|
-
private readonly
|
|
161
|
+
private readonly webFunction;
|
|
162
|
+
private readonly resource;
|
|
163
|
+
private weights;
|
|
164
|
+
private routed;
|
|
165
|
+
private readonly gradual;
|
|
78
166
|
private lookup?;
|
|
79
167
|
private constructor();
|
|
80
168
|
/**
|
|
@@ -83,5 +171,66 @@ export declare class WebFunctionEndpoint extends Construct {
|
|
|
83
171
|
* @param region one of `regions`
|
|
84
172
|
*/
|
|
85
173
|
regionalUrl(region: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* Routes the endpoint to `revision` instead of the function's current revision, optionally sharing
|
|
176
|
+
* traffic with one more revision (`additionalRevisions`, which gets its weight; `revision` gets the rest).
|
|
177
|
+
*
|
|
178
|
+
* Use it to keep an endpoint on an earlier revision (`WebFunctionRevision.fromRevisionAttributes`),
|
|
179
|
+
* or to send part of the traffic to the current revision:
|
|
180
|
+
* `fn.endpoint.routeTraffic(previous, [{ revision: fn.currentRevision, weight: 0.1 }])`.
|
|
181
|
+
* Can be called once per endpoint, and not on one created with `revision` or `additionalRevisions`.
|
|
182
|
+
*/
|
|
183
|
+
routeTraffic(revision: IWebFunctionRevision, additionalRevisions?: WebFunctionRevisionWeight[]): void;
|
|
184
|
+
/**
|
|
185
|
+
* The IDs of the revisions this endpoint routes to.
|
|
186
|
+
*
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
_revisionIds(): string[];
|
|
190
|
+
/**
|
|
191
|
+
* A metric of this endpoint in `AWS/Lambda/Web` (dimensions `FunctionName` and `EndpointName`).
|
|
192
|
+
*
|
|
193
|
+
* Metrics are published in the region that served the request: pass `region` for one of the endpoint's
|
|
194
|
+
* other regions. An alarm can only use metrics from its own stack's region.
|
|
195
|
+
*
|
|
196
|
+
* @default - sum over 1 minute, in the home region
|
|
197
|
+
*/
|
|
198
|
+
metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
199
|
+
/** Requests the endpoint served (`ExecutedRequests`). There's no separate count of successful (2XX) responses. */
|
|
200
|
+
metricRequests(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
201
|
+
/**
|
|
202
|
+
* Requests answered with a 4XX status (`HTTPResponseStatusClass4XX`), including 429s from `rateLimit` and `maxEnvironments`.
|
|
203
|
+
* The metric only exists once it's non-zero, so alarms should treat missing data as not breaching.
|
|
204
|
+
*/
|
|
205
|
+
metricClientErrors(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
206
|
+
/**
|
|
207
|
+
* Requests answered with a 5XX status (`HTTPResponseStatusClass5XX`). Includes the platform's 503s while the endpoint
|
|
208
|
+
* scales up for a sudden burst, not only your application's errors. The metric only exists once it's non-zero.
|
|
209
|
+
*/
|
|
210
|
+
metricServerErrors(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
211
|
+
/** The percentage of requests answered with a 4XX status (math expression; periods with no 4XX count as 0). */
|
|
212
|
+
metricClientErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.MathExpression;
|
|
213
|
+
/** The percentage of requests answered with a 5XX status (math expression; periods with no 5XX count as 0). */
|
|
214
|
+
metricServerErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.MathExpression;
|
|
215
|
+
/**
|
|
216
|
+
* Execution environments serving the endpoint (`EndpointActiveEnvironments`), to compare with `maxEnvironments`.
|
|
217
|
+
*
|
|
218
|
+
* @default - maximum over 1 minute, in the home region
|
|
219
|
+
*/
|
|
220
|
+
metricActiveEnvironments(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
221
|
+
/** Requests rejected with 429 because the endpoint reached its `rateLimit` (`EndpointRequestThrottles`). */
|
|
222
|
+
metricRequestThrottles(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
223
|
+
/** Requests rejected with 429 because the endpoint reached `maxEnvironments` (`EndpointActiveEnvironmentThrottles`). */
|
|
224
|
+
metricEnvironmentThrottles(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
|
|
225
|
+
/**
|
|
226
|
+
* Allows `grantee` to call this endpoint. Shortcut for `grants.invoke(grantee)`.
|
|
227
|
+
* [disable-awslint:no-grants]
|
|
228
|
+
*/
|
|
229
|
+
grantInvoke(grantee: iam.IGrantable): iam.Grant;
|
|
230
|
+
private metricIds;
|
|
231
|
+
private rate;
|
|
232
|
+
private usageMetric;
|
|
233
|
+
/** One alarm per threshold in every serving region: a CloudFormation alarm at home, a custom resource elsewhere. Returns their ARNs. */
|
|
234
|
+
private createRollbackAlarms;
|
|
86
235
|
}
|
|
87
236
|
export {};
|