@jaypie/constructs 1.1.34 → 1.1.36-beta.1
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/dist/cjs/JaypieLambda.d.ts +3 -2
- package/dist/cjs/index.cjs +224 -218
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieLambda.d.ts +3 -2
- package/dist/esm/index.js +223 -217
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -35,11 +35,12 @@ export interface JaypieLambdaProps {
|
|
|
35
35
|
}
|
|
36
36
|
export declare class JaypieLambda extends Construct implements lambda.IFunction {
|
|
37
37
|
private readonly _lambda;
|
|
38
|
-
private readonly
|
|
38
|
+
private readonly _provisioned?;
|
|
39
39
|
private readonly _code;
|
|
40
|
+
private readonly _reference;
|
|
40
41
|
constructor(scope: Construct, id: string, props: JaypieLambdaProps);
|
|
41
42
|
get lambda(): lambda.Function;
|
|
42
|
-
get
|
|
43
|
+
get provisioned(): lambda.Alias | undefined;
|
|
43
44
|
get code(): lambda.Code;
|
|
44
45
|
get functionArn(): string;
|
|
45
46
|
get functionName(): string;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import * as cdk from 'aws-cdk-lib';
|
|
3
|
-
import { Tags,
|
|
3
|
+
import { Tags, Duration, Stack, RemovalPolicy, Fn, CfnOutput, SecretValue } from 'aws-cdk-lib';
|
|
4
4
|
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
|
|
5
5
|
import * as apiGateway from 'aws-cdk-lib/aws-apigateway';
|
|
6
6
|
import * as route53 from 'aws-cdk-lib/aws-route53';
|
|
7
7
|
import { HostedZone } from 'aws-cdk-lib/aws-route53';
|
|
8
8
|
import * as route53Targets from 'aws-cdk-lib/aws-route53-targets';
|
|
9
9
|
import { CDK as CDK$2, mergeDomain, isValidSubdomain, ConfigurationError, isValidHostname } from '@jaypie/cdk';
|
|
10
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
11
|
+
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
|
|
10
12
|
import * as s3 from 'aws-cdk-lib/aws-s3';
|
|
11
13
|
import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
|
|
12
|
-
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
13
14
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
14
15
|
import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
|
|
15
|
-
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
|
|
16
16
|
import { ServicePrincipal, Role, FederatedPrincipal, PolicyStatement, Effect } from 'aws-cdk-lib/aws-iam';
|
|
17
17
|
import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
|
|
18
18
|
import * as sso from 'aws-cdk-lib/aws-sso';
|
|
@@ -106,186 +106,6 @@ function stackTagger(stack, { name } = {}) {
|
|
|
106
106
|
return true;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
class JaypieApiGateway extends Construct {
|
|
110
|
-
constructor(scope, id, props) {
|
|
111
|
-
super(scope, id);
|
|
112
|
-
const { certificate = true, handler, host: propsHost, name, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
|
|
113
|
-
// Determine zone from props or environment
|
|
114
|
-
let zone = propsZone;
|
|
115
|
-
if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
|
|
116
|
-
zone = process.env.CDK_ENV_API_HOSTED_ZONE;
|
|
117
|
-
}
|
|
118
|
-
// Determine host from props or environment
|
|
119
|
-
let host = propsHost;
|
|
120
|
-
if (!host) {
|
|
121
|
-
if (process.env.CDK_ENV_API_HOST_NAME) {
|
|
122
|
-
host = process.env.CDK_ENV_API_HOST_NAME;
|
|
123
|
-
}
|
|
124
|
-
else if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
125
|
-
process.env.CDK_ENV_API_HOSTED_ZONE) {
|
|
126
|
-
host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const apiGatewayName = name || constructEnvName("ApiGateway");
|
|
130
|
-
const certificateName = constructEnvName("Certificate");
|
|
131
|
-
const apiDomainName = constructEnvName("ApiDomainName");
|
|
132
|
-
let hostedZone;
|
|
133
|
-
let certificateToUse;
|
|
134
|
-
if (host && zone) {
|
|
135
|
-
if (typeof zone === "string") {
|
|
136
|
-
hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
|
|
137
|
-
domainName: zone,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
hostedZone = zone;
|
|
142
|
-
}
|
|
143
|
-
if (certificate === true) {
|
|
144
|
-
certificateToUse = new acm.Certificate(this, certificateName, {
|
|
145
|
-
domainName: host,
|
|
146
|
-
validation: acm.CertificateValidation.fromDns(hostedZone),
|
|
147
|
-
});
|
|
148
|
-
Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, CDK$2.ROLE.HOSTING);
|
|
149
|
-
}
|
|
150
|
-
else if (typeof certificate === "object") {
|
|
151
|
-
certificateToUse = certificate;
|
|
152
|
-
}
|
|
153
|
-
this._certificate = certificateToUse;
|
|
154
|
-
this._host = host;
|
|
155
|
-
}
|
|
156
|
-
const {
|
|
157
|
-
// * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
|
|
158
|
-
// Ignore the variables we already assigned to other properties
|
|
159
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
160
|
-
certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
|
|
161
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
162
|
-
...lambdaRestApiProps } = props;
|
|
163
|
-
this._api = new apiGateway.LambdaRestApi(this, apiGatewayName, {
|
|
164
|
-
handler,
|
|
165
|
-
...lambdaRestApiProps,
|
|
166
|
-
});
|
|
167
|
-
Tags.of(this._api).add(CDK$2.TAG.ROLE, roleTag);
|
|
168
|
-
if (host && certificateToUse && hostedZone) {
|
|
169
|
-
this._domainName = this._api.addDomainName(apiDomainName, {
|
|
170
|
-
domainName: host,
|
|
171
|
-
certificate: certificateToUse,
|
|
172
|
-
});
|
|
173
|
-
Tags.of(this._domainName).add(CDK$2.TAG.ROLE, roleTag);
|
|
174
|
-
const record = new route53.ARecord(this, "AliasRecord", {
|
|
175
|
-
recordName: host,
|
|
176
|
-
target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(this._domainName)),
|
|
177
|
-
zone: hostedZone,
|
|
178
|
-
});
|
|
179
|
-
Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
get api() {
|
|
183
|
-
return this._api;
|
|
184
|
-
}
|
|
185
|
-
get url() {
|
|
186
|
-
return this._api.url;
|
|
187
|
-
}
|
|
188
|
-
get certificateArn() {
|
|
189
|
-
return this._certificate?.certificateArn;
|
|
190
|
-
}
|
|
191
|
-
get domainName() {
|
|
192
|
-
return this._domainName?.domainName;
|
|
193
|
-
}
|
|
194
|
-
get host() {
|
|
195
|
-
return this._host;
|
|
196
|
-
}
|
|
197
|
-
get restApiId() {
|
|
198
|
-
return this._api.restApiId;
|
|
199
|
-
}
|
|
200
|
-
get restApiName() {
|
|
201
|
-
return this._api.restApiName;
|
|
202
|
-
}
|
|
203
|
-
get restApiRootResourceId() {
|
|
204
|
-
return this._api.restApiRootResourceId;
|
|
205
|
-
}
|
|
206
|
-
get deploymentStage() {
|
|
207
|
-
return this._api.deploymentStage;
|
|
208
|
-
}
|
|
209
|
-
get domainNameAliasDomainName() {
|
|
210
|
-
return this._domainName?.domainNameAliasDomainName;
|
|
211
|
-
}
|
|
212
|
-
get domainNameAliasHostedZoneId() {
|
|
213
|
-
return this._domainName?.domainNameAliasHostedZoneId;
|
|
214
|
-
}
|
|
215
|
-
get root() {
|
|
216
|
-
return this._api.root;
|
|
217
|
-
}
|
|
218
|
-
get env() {
|
|
219
|
-
return {
|
|
220
|
-
account: Stack.of(this).account,
|
|
221
|
-
region: Stack.of(this).region,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
get stack() {
|
|
225
|
-
return this._api.stack;
|
|
226
|
-
}
|
|
227
|
-
arnForExecuteApi(method, path, stage) {
|
|
228
|
-
return this._api.arnForExecuteApi(method, path, stage);
|
|
229
|
-
}
|
|
230
|
-
metric(metricName, props) {
|
|
231
|
-
return this._api.metric(metricName, props);
|
|
232
|
-
}
|
|
233
|
-
metricCacheHitCount(props) {
|
|
234
|
-
return this._api.metricCacheHitCount(props);
|
|
235
|
-
}
|
|
236
|
-
metricCacheMissCount(props) {
|
|
237
|
-
return this._api.metricCacheMissCount(props);
|
|
238
|
-
}
|
|
239
|
-
metricClientError(props) {
|
|
240
|
-
return this._api.metricClientError(props);
|
|
241
|
-
}
|
|
242
|
-
metricCount(props) {
|
|
243
|
-
return this._api.metricCount(props);
|
|
244
|
-
}
|
|
245
|
-
metricIntegrationLatency(props) {
|
|
246
|
-
return this._api.metricIntegrationLatency(props);
|
|
247
|
-
}
|
|
248
|
-
metricLatency(props) {
|
|
249
|
-
return this._api.metricLatency(props);
|
|
250
|
-
}
|
|
251
|
-
metricServerError(props) {
|
|
252
|
-
return this._api.metricServerError(props);
|
|
253
|
-
}
|
|
254
|
-
applyRemovalPolicy(policy) {
|
|
255
|
-
this._api.applyRemovalPolicy(policy);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
class JaypieStack extends Stack {
|
|
260
|
-
constructor(scope, id, props = {}) {
|
|
261
|
-
const { key, ...stackProps } = props;
|
|
262
|
-
// Handle stackName
|
|
263
|
-
if (!stackProps.stackName) {
|
|
264
|
-
stackProps.stackName = constructStackName(key);
|
|
265
|
-
}
|
|
266
|
-
// Handle env
|
|
267
|
-
stackProps.env = {
|
|
268
|
-
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
269
|
-
region: process.env.CDK_DEFAULT_REGION,
|
|
270
|
-
...stackProps.env,
|
|
271
|
-
};
|
|
272
|
-
super(scope, id, stackProps);
|
|
273
|
-
// Apply tags
|
|
274
|
-
stackTagger(this, { name: stackProps.stackName });
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
class JaypieAppStack extends JaypieStack {
|
|
279
|
-
constructor(scope, id, props = {}) {
|
|
280
|
-
const { key = "app", ...stackProps } = props;
|
|
281
|
-
// Handle stackName
|
|
282
|
-
if (!stackProps.stackName) {
|
|
283
|
-
stackProps.stackName = constructStackName(key);
|
|
284
|
-
}
|
|
285
|
-
super(scope, id, { key, ...stackProps });
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
109
|
class JaypieLambda extends Construct {
|
|
290
110
|
constructor(scope, id, props) {
|
|
291
111
|
super(scope, id);
|
|
@@ -428,7 +248,6 @@ class JaypieLambda extends Construct {
|
|
|
428
248
|
});
|
|
429
249
|
// Grant read permissions for JaypieEnvSecrets
|
|
430
250
|
secrets.forEach((secret) => {
|
|
431
|
-
secret.grantRead(this);
|
|
432
251
|
secret.grantRead(this._lambda);
|
|
433
252
|
});
|
|
434
253
|
// Grant Datadog API key read permission if applicable
|
|
@@ -441,13 +260,13 @@ class JaypieLambda extends Construct {
|
|
|
441
260
|
// Use currentVersion which is auto-published with proper configuration
|
|
442
261
|
const version = this._lambda.currentVersion;
|
|
443
262
|
// Create alias for provisioned concurrency
|
|
444
|
-
this.
|
|
263
|
+
this._provisioned = new lambda.Alias(this, "ProvisionedAlias", {
|
|
445
264
|
aliasName: "provisioned",
|
|
446
265
|
version,
|
|
447
266
|
provisionedConcurrentExecutions,
|
|
448
267
|
});
|
|
449
268
|
// Add explicit dependencies to ensure proper creation order
|
|
450
|
-
this.
|
|
269
|
+
this._provisioned.node.addDependency(version);
|
|
451
270
|
}
|
|
452
271
|
if (roleTag) {
|
|
453
272
|
Tags.of(this._lambda).add(CDK$2.TAG.ROLE, roleTag);
|
|
@@ -455,100 +274,230 @@ class JaypieLambda extends Construct {
|
|
|
455
274
|
if (vendorTag) {
|
|
456
275
|
Tags.of(this._lambda).add(CDK$2.TAG.VENDOR, vendorTag);
|
|
457
276
|
}
|
|
277
|
+
// Assign _reference based on provisioned state
|
|
278
|
+
this._reference =
|
|
279
|
+
this._provisioned !== undefined ? this._provisioned : this._lambda;
|
|
458
280
|
}
|
|
459
281
|
// Public accessors
|
|
460
282
|
get lambda() {
|
|
461
283
|
return this._lambda;
|
|
462
284
|
}
|
|
463
|
-
get
|
|
464
|
-
return this.
|
|
285
|
+
get provisioned() {
|
|
286
|
+
return this._provisioned;
|
|
465
287
|
}
|
|
466
288
|
get code() {
|
|
467
289
|
return this._code;
|
|
468
290
|
}
|
|
469
291
|
// IFunction implementation
|
|
470
292
|
get functionArn() {
|
|
471
|
-
return this.
|
|
293
|
+
return this._reference.functionArn;
|
|
472
294
|
}
|
|
473
295
|
get functionName() {
|
|
474
|
-
return this.
|
|
296
|
+
return this._reference.functionName;
|
|
475
297
|
}
|
|
476
298
|
get grantPrincipal() {
|
|
477
|
-
return this.
|
|
299
|
+
return this._reference.grantPrincipal;
|
|
478
300
|
}
|
|
479
301
|
get role() {
|
|
480
|
-
return this.
|
|
302
|
+
return this._reference.role;
|
|
481
303
|
}
|
|
482
304
|
get architecture() {
|
|
483
|
-
return this.
|
|
305
|
+
return this._reference.architecture;
|
|
484
306
|
}
|
|
485
307
|
get connections() {
|
|
486
|
-
return this.
|
|
308
|
+
return this._reference.connections;
|
|
487
309
|
}
|
|
488
310
|
get isBoundToVpc() {
|
|
489
|
-
return this.
|
|
311
|
+
return this._reference.isBoundToVpc;
|
|
490
312
|
}
|
|
491
313
|
get latestVersion() {
|
|
492
|
-
return this.
|
|
314
|
+
return this._reference.latestVersion;
|
|
493
315
|
}
|
|
494
316
|
get permissionsNode() {
|
|
495
|
-
return this.
|
|
317
|
+
return this._reference.permissionsNode;
|
|
496
318
|
}
|
|
497
319
|
get resourceArnsForGrantInvoke() {
|
|
498
|
-
return
|
|
499
|
-
this._lambda.resourceArnsForGrantInvoke);
|
|
320
|
+
return this._reference.resourceArnsForGrantInvoke;
|
|
500
321
|
}
|
|
501
322
|
addEventSource(source) {
|
|
502
|
-
this.
|
|
323
|
+
this._reference.addEventSource(source);
|
|
503
324
|
}
|
|
504
325
|
addEventSourceMapping(id, options) {
|
|
505
|
-
return this.
|
|
326
|
+
return this._reference.addEventSourceMapping(id, options);
|
|
506
327
|
}
|
|
507
328
|
addFunctionUrl(options) {
|
|
508
|
-
return this.
|
|
329
|
+
return this._reference.addFunctionUrl(options);
|
|
509
330
|
}
|
|
510
331
|
addPermission(id, permission) {
|
|
511
|
-
this.
|
|
332
|
+
this._reference.addPermission(id, permission);
|
|
512
333
|
}
|
|
513
334
|
addToRolePolicy(statement) {
|
|
514
|
-
this.
|
|
335
|
+
this._reference.addToRolePolicy(statement);
|
|
515
336
|
}
|
|
516
337
|
addEnvironment(key, value, options) {
|
|
517
338
|
return this._lambda.addEnvironment(key, value, options);
|
|
518
339
|
}
|
|
519
340
|
configureAsyncInvoke(options) {
|
|
520
|
-
this.
|
|
341
|
+
this._reference.configureAsyncInvoke(options);
|
|
521
342
|
}
|
|
522
343
|
grantInvoke(grantee) {
|
|
523
|
-
return
|
|
344
|
+
return this._reference.grantInvoke(grantee);
|
|
524
345
|
}
|
|
525
346
|
grantInvokeCompositePrincipal(compositePrincipal) {
|
|
526
|
-
return this.
|
|
347
|
+
return this._reference.grantInvokeCompositePrincipal(compositePrincipal);
|
|
527
348
|
}
|
|
528
349
|
grantInvokeUrl(grantee) {
|
|
529
|
-
return this.
|
|
350
|
+
return this._reference.grantInvokeUrl(grantee);
|
|
530
351
|
}
|
|
531
352
|
metric(metricName, props) {
|
|
532
|
-
return this.
|
|
353
|
+
return this._reference.metric(metricName, props);
|
|
533
354
|
}
|
|
534
355
|
metricDuration(props) {
|
|
535
|
-
return this.
|
|
356
|
+
return this._reference.metricDuration(props);
|
|
536
357
|
}
|
|
537
358
|
metricErrors(props) {
|
|
538
|
-
return this.
|
|
359
|
+
return this._reference.metricErrors(props);
|
|
539
360
|
}
|
|
540
361
|
metricInvocations(props) {
|
|
541
|
-
return this.
|
|
362
|
+
return this._reference.metricInvocations(props);
|
|
542
363
|
}
|
|
543
364
|
metricThrottles(props) {
|
|
544
|
-
return this.
|
|
365
|
+
return this._reference.metricThrottles(props);
|
|
545
366
|
}
|
|
546
367
|
// Additional IFunction implementation
|
|
547
368
|
grantInvokeLatestVersion(grantee) {
|
|
548
|
-
return this.
|
|
369
|
+
return this._reference.grantInvokeLatestVersion(grantee);
|
|
549
370
|
}
|
|
550
371
|
grantInvokeVersion(grantee, version) {
|
|
551
|
-
return this.
|
|
372
|
+
return this._reference.grantInvokeVersion(grantee, version);
|
|
373
|
+
}
|
|
374
|
+
get env() {
|
|
375
|
+
return {
|
|
376
|
+
account: Stack.of(this).account,
|
|
377
|
+
region: Stack.of(this).region,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
get stack() {
|
|
381
|
+
return this._reference.stack;
|
|
382
|
+
}
|
|
383
|
+
applyRemovalPolicy(policy) {
|
|
384
|
+
this._reference.applyRemovalPolicy(policy);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
class JaypieApiGateway extends Construct {
|
|
389
|
+
constructor(scope, id, props) {
|
|
390
|
+
super(scope, id);
|
|
391
|
+
const { certificate = true, handler, host: propsHost, name, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
|
|
392
|
+
// Determine zone from props or environment
|
|
393
|
+
let zone = propsZone;
|
|
394
|
+
if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
|
|
395
|
+
zone = process.env.CDK_ENV_API_HOSTED_ZONE;
|
|
396
|
+
}
|
|
397
|
+
// Determine host from props or environment
|
|
398
|
+
let host = propsHost;
|
|
399
|
+
if (!host) {
|
|
400
|
+
if (process.env.CDK_ENV_API_HOST_NAME) {
|
|
401
|
+
host = process.env.CDK_ENV_API_HOST_NAME;
|
|
402
|
+
}
|
|
403
|
+
else if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
404
|
+
process.env.CDK_ENV_API_HOSTED_ZONE) {
|
|
405
|
+
host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const apiGatewayName = name || constructEnvName("ApiGateway");
|
|
409
|
+
const certificateName = constructEnvName("Certificate");
|
|
410
|
+
const apiDomainName = constructEnvName("ApiDomainName");
|
|
411
|
+
let hostedZone;
|
|
412
|
+
let certificateToUse;
|
|
413
|
+
if (host && zone) {
|
|
414
|
+
if (typeof zone === "string") {
|
|
415
|
+
hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
|
|
416
|
+
domainName: zone,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
hostedZone = zone;
|
|
421
|
+
}
|
|
422
|
+
if (certificate === true) {
|
|
423
|
+
certificateToUse = new acm.Certificate(this, certificateName, {
|
|
424
|
+
domainName: host,
|
|
425
|
+
validation: acm.CertificateValidation.fromDns(hostedZone),
|
|
426
|
+
});
|
|
427
|
+
Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, CDK$2.ROLE.HOSTING);
|
|
428
|
+
}
|
|
429
|
+
else if (typeof certificate === "object") {
|
|
430
|
+
certificateToUse = certificate;
|
|
431
|
+
}
|
|
432
|
+
this._certificate = certificateToUse;
|
|
433
|
+
this._host = host;
|
|
434
|
+
}
|
|
435
|
+
const {
|
|
436
|
+
// * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
|
|
437
|
+
// Ignore the variables we already assigned to other properties
|
|
438
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
439
|
+
certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
|
|
440
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
441
|
+
...lambdaRestApiProps } = props;
|
|
442
|
+
// Check if handler is a JaypieLambda instance and use provisioned alias if available
|
|
443
|
+
let handlerToUse = handler;
|
|
444
|
+
if (handler instanceof JaypieLambda && handler.provisioned) {
|
|
445
|
+
handlerToUse = handler.provisioned;
|
|
446
|
+
}
|
|
447
|
+
this._api = new apiGateway.LambdaRestApi(this, apiGatewayName, {
|
|
448
|
+
handler: handlerToUse,
|
|
449
|
+
...lambdaRestApiProps,
|
|
450
|
+
});
|
|
451
|
+
Tags.of(this._api).add(CDK$2.TAG.ROLE, roleTag);
|
|
452
|
+
if (host && certificateToUse && hostedZone) {
|
|
453
|
+
this._domainName = this._api.addDomainName(apiDomainName, {
|
|
454
|
+
domainName: host,
|
|
455
|
+
certificate: certificateToUse,
|
|
456
|
+
});
|
|
457
|
+
Tags.of(this._domainName).add(CDK$2.TAG.ROLE, roleTag);
|
|
458
|
+
const record = new route53.ARecord(this, "AliasRecord", {
|
|
459
|
+
recordName: host,
|
|
460
|
+
target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(this._domainName)),
|
|
461
|
+
zone: hostedZone,
|
|
462
|
+
});
|
|
463
|
+
Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
get api() {
|
|
467
|
+
return this._api;
|
|
468
|
+
}
|
|
469
|
+
get url() {
|
|
470
|
+
return this._api.url;
|
|
471
|
+
}
|
|
472
|
+
get certificateArn() {
|
|
473
|
+
return this._certificate?.certificateArn;
|
|
474
|
+
}
|
|
475
|
+
get domainName() {
|
|
476
|
+
return this._domainName?.domainName;
|
|
477
|
+
}
|
|
478
|
+
get host() {
|
|
479
|
+
return this._host;
|
|
480
|
+
}
|
|
481
|
+
get restApiId() {
|
|
482
|
+
return this._api.restApiId;
|
|
483
|
+
}
|
|
484
|
+
get restApiName() {
|
|
485
|
+
return this._api.restApiName;
|
|
486
|
+
}
|
|
487
|
+
get restApiRootResourceId() {
|
|
488
|
+
return this._api.restApiRootResourceId;
|
|
489
|
+
}
|
|
490
|
+
get deploymentStage() {
|
|
491
|
+
return this._api.deploymentStage;
|
|
492
|
+
}
|
|
493
|
+
get domainNameAliasDomainName() {
|
|
494
|
+
return this._domainName?.domainNameAliasDomainName;
|
|
495
|
+
}
|
|
496
|
+
get domainNameAliasHostedZoneId() {
|
|
497
|
+
return this._domainName?.domainNameAliasHostedZoneId;
|
|
498
|
+
}
|
|
499
|
+
get root() {
|
|
500
|
+
return this._api.root;
|
|
552
501
|
}
|
|
553
502
|
get env() {
|
|
554
503
|
return {
|
|
@@ -557,10 +506,67 @@ class JaypieLambda extends Construct {
|
|
|
557
506
|
};
|
|
558
507
|
}
|
|
559
508
|
get stack() {
|
|
560
|
-
return this.
|
|
509
|
+
return this._api.stack;
|
|
510
|
+
}
|
|
511
|
+
arnForExecuteApi(method, path, stage) {
|
|
512
|
+
return this._api.arnForExecuteApi(method, path, stage);
|
|
513
|
+
}
|
|
514
|
+
metric(metricName, props) {
|
|
515
|
+
return this._api.metric(metricName, props);
|
|
516
|
+
}
|
|
517
|
+
metricCacheHitCount(props) {
|
|
518
|
+
return this._api.metricCacheHitCount(props);
|
|
519
|
+
}
|
|
520
|
+
metricCacheMissCount(props) {
|
|
521
|
+
return this._api.metricCacheMissCount(props);
|
|
522
|
+
}
|
|
523
|
+
metricClientError(props) {
|
|
524
|
+
return this._api.metricClientError(props);
|
|
525
|
+
}
|
|
526
|
+
metricCount(props) {
|
|
527
|
+
return this._api.metricCount(props);
|
|
528
|
+
}
|
|
529
|
+
metricIntegrationLatency(props) {
|
|
530
|
+
return this._api.metricIntegrationLatency(props);
|
|
531
|
+
}
|
|
532
|
+
metricLatency(props) {
|
|
533
|
+
return this._api.metricLatency(props);
|
|
534
|
+
}
|
|
535
|
+
metricServerError(props) {
|
|
536
|
+
return this._api.metricServerError(props);
|
|
561
537
|
}
|
|
562
538
|
applyRemovalPolicy(policy) {
|
|
563
|
-
this.
|
|
539
|
+
this._api.applyRemovalPolicy(policy);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
class JaypieStack extends Stack {
|
|
544
|
+
constructor(scope, id, props = {}) {
|
|
545
|
+
const { key, ...stackProps } = props;
|
|
546
|
+
// Handle stackName
|
|
547
|
+
if (!stackProps.stackName) {
|
|
548
|
+
stackProps.stackName = constructStackName(key);
|
|
549
|
+
}
|
|
550
|
+
// Handle env
|
|
551
|
+
stackProps.env = {
|
|
552
|
+
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
553
|
+
region: process.env.CDK_DEFAULT_REGION,
|
|
554
|
+
...stackProps.env,
|
|
555
|
+
};
|
|
556
|
+
super(scope, id, stackProps);
|
|
557
|
+
// Apply tags
|
|
558
|
+
stackTagger(this, { name: stackProps.stackName });
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
class JaypieAppStack extends JaypieStack {
|
|
563
|
+
constructor(scope, id, props = {}) {
|
|
564
|
+
const { key = "app", ...stackProps } = props;
|
|
565
|
+
// Handle stackName
|
|
566
|
+
if (!stackProps.stackName) {
|
|
567
|
+
stackProps.stackName = constructStackName(key);
|
|
568
|
+
}
|
|
569
|
+
super(scope, id, { key, ...stackProps });
|
|
564
570
|
}
|
|
565
571
|
}
|
|
566
572
|
|