@jaypie/constructs 1.1.33 → 1.1.35

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.
@@ -35,11 +35,11 @@ export interface JaypieLambdaProps {
35
35
  }
36
36
  export declare class JaypieLambda extends Construct implements lambda.IFunction {
37
37
  private readonly _lambda;
38
- private readonly _alias?;
38
+ private readonly _provisioned?;
39
39
  private readonly _code;
40
40
  constructor(scope: Construct, id: string, props: JaypieLambdaProps);
41
41
  get lambda(): lambda.Function;
42
- get alias(): lambda.Alias | undefined;
42
+ get provisioned(): lambda.Alias | undefined;
43
43
  get code(): lambda.Code;
44
44
  get functionArn(): string;
45
45
  get functionName(): string;
@@ -7,12 +7,12 @@ var apiGateway = require('aws-cdk-lib/aws-apigateway');
7
7
  var route53 = require('aws-cdk-lib/aws-route53');
8
8
  var route53Targets = require('aws-cdk-lib/aws-route53-targets');
9
9
  var cdk = require('@jaypie/cdk');
10
+ var lambda = require('aws-cdk-lib/aws-lambda');
11
+ var secretsmanager = require('aws-cdk-lib/aws-secretsmanager');
10
12
  var s3 = require('aws-cdk-lib/aws-s3');
11
13
  var s3n = require('aws-cdk-lib/aws-s3-notifications');
12
- var lambda = require('aws-cdk-lib/aws-lambda');
13
14
  var sqs = require('aws-cdk-lib/aws-sqs');
14
15
  var lambdaEventSources = require('aws-cdk-lib/aws-lambda-event-sources');
15
- var secretsmanager = require('aws-cdk-lib/aws-secretsmanager');
16
16
  var awsIam = require('aws-cdk-lib/aws-iam');
17
17
  var awsLogs = require('aws-cdk-lib/aws-logs');
18
18
  var sso = require('aws-cdk-lib/aws-sso');
@@ -41,12 +41,12 @@ var acm__namespace = /*#__PURE__*/_interopNamespaceDefault(acm);
41
41
  var apiGateway__namespace = /*#__PURE__*/_interopNamespaceDefault(apiGateway);
42
42
  var route53__namespace = /*#__PURE__*/_interopNamespaceDefault(route53);
43
43
  var route53Targets__namespace = /*#__PURE__*/_interopNamespaceDefault(route53Targets);
44
+ var lambda__namespace = /*#__PURE__*/_interopNamespaceDefault(lambda);
45
+ var secretsmanager__namespace = /*#__PURE__*/_interopNamespaceDefault(secretsmanager);
44
46
  var s3__namespace = /*#__PURE__*/_interopNamespaceDefault(s3);
45
47
  var s3n__namespace = /*#__PURE__*/_interopNamespaceDefault(s3n);
46
- var lambda__namespace = /*#__PURE__*/_interopNamespaceDefault(lambda);
47
48
  var sqs__namespace = /*#__PURE__*/_interopNamespaceDefault(sqs);
48
49
  var lambdaEventSources__namespace = /*#__PURE__*/_interopNamespaceDefault(lambdaEventSources);
49
- var secretsmanager__namespace = /*#__PURE__*/_interopNamespaceDefault(secretsmanager);
50
50
  var sso__namespace = /*#__PURE__*/_interopNamespaceDefault(sso);
51
51
  var cloudfront__namespace = /*#__PURE__*/_interopNamespaceDefault(cloudfront);
52
52
  var origins__namespace = /*#__PURE__*/_interopNamespaceDefault(origins);
@@ -138,192 +138,35 @@ function stackTagger(stack, { name } = {}) {
138
138
  return true;
139
139
  }
140
140
 
141
- class JaypieApiGateway extends constructs.Construct {
142
- constructor(scope, id, props) {
143
- super(scope, id);
144
- const { certificate = true, handler, host: propsHost, name, roleTag = cdk.CDK.ROLE.API, zone: propsZone, } = props;
145
- // Determine zone from props or environment
146
- let zone = propsZone;
147
- if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
148
- zone = process.env.CDK_ENV_API_HOSTED_ZONE;
149
- }
150
- // Determine host from props or environment
151
- let host = propsHost;
152
- if (!host) {
153
- if (process.env.CDK_ENV_API_HOST_NAME) {
154
- host = process.env.CDK_ENV_API_HOST_NAME;
155
- }
156
- else if (process.env.CDK_ENV_API_SUBDOMAIN &&
157
- process.env.CDK_ENV_API_HOSTED_ZONE) {
158
- host = cdk.mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
159
- }
160
- }
161
- const apiGatewayName = name || constructEnvName("ApiGateway");
162
- const certificateName = constructEnvName("Certificate");
163
- const apiDomainName = constructEnvName("ApiDomainName");
164
- let hostedZone;
165
- let certificateToUse;
166
- if (host && zone) {
167
- if (typeof zone === "string") {
168
- hostedZone = route53__namespace.HostedZone.fromLookup(this, "HostedZone", {
169
- domainName: zone,
170
- });
171
- }
172
- else {
173
- hostedZone = zone;
174
- }
175
- if (certificate === true) {
176
- certificateToUse = new acm__namespace.Certificate(this, certificateName, {
177
- domainName: host,
178
- validation: acm__namespace.CertificateValidation.fromDns(hostedZone),
179
- });
180
- cdk$1.Tags.of(certificateToUse).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.HOSTING);
181
- }
182
- else if (typeof certificate === "object") {
183
- certificateToUse = certificate;
184
- }
185
- this._certificate = certificateToUse;
186
- this._host = host;
187
- }
188
- const {
189
- // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
190
- // Ignore the variables we already assigned to other properties
191
- /* eslint-disable @typescript-eslint/no-unused-vars */
192
- certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
193
- /* eslint-enable @typescript-eslint/no-unused-vars */
194
- ...lambdaRestApiProps } = props;
195
- this._api = new apiGateway__namespace.LambdaRestApi(this, apiGatewayName, {
196
- handler,
197
- ...lambdaRestApiProps,
198
- });
199
- cdk$1.Tags.of(this._api).add(cdk.CDK.TAG.ROLE, roleTag);
200
- if (host && certificateToUse && hostedZone) {
201
- this._domainName = this._api.addDomainName(apiDomainName, {
202
- domainName: host,
203
- certificate: certificateToUse,
204
- });
205
- cdk$1.Tags.of(this._domainName).add(cdk.CDK.TAG.ROLE, roleTag);
206
- const record = new route53__namespace.ARecord(this, "AliasRecord", {
207
- recordName: host,
208
- target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.ApiGatewayDomain(this._domainName)),
209
- zone: hostedZone,
210
- });
211
- cdk$1.Tags.of(record).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.NETWORKING);
212
- }
213
- }
214
- get api() {
215
- return this._api;
216
- }
217
- get url() {
218
- return this._api.url;
219
- }
220
- get certificateArn() {
221
- return this._certificate?.certificateArn;
222
- }
223
- get domainName() {
224
- return this._domainName?.domainName;
225
- }
226
- get host() {
227
- return this._host;
228
- }
229
- get restApiId() {
230
- return this._api.restApiId;
231
- }
232
- get restApiName() {
233
- return this._api.restApiName;
234
- }
235
- get restApiRootResourceId() {
236
- return this._api.restApiRootResourceId;
237
- }
238
- get deploymentStage() {
239
- return this._api.deploymentStage;
240
- }
241
- get domainNameAliasDomainName() {
242
- return this._domainName?.domainNameAliasDomainName;
243
- }
244
- get domainNameAliasHostedZoneId() {
245
- return this._domainName?.domainNameAliasHostedZoneId;
246
- }
247
- get root() {
248
- return this._api.root;
249
- }
250
- get env() {
251
- return {
252
- account: cdk$1.Stack.of(this).account,
253
- region: cdk$1.Stack.of(this).region,
254
- };
255
- }
256
- get stack() {
257
- return this._api.stack;
258
- }
259
- arnForExecuteApi(method, path, stage) {
260
- return this._api.arnForExecuteApi(method, path, stage);
261
- }
262
- metric(metricName, props) {
263
- return this._api.metric(metricName, props);
264
- }
265
- metricCacheHitCount(props) {
266
- return this._api.metricCacheHitCount(props);
267
- }
268
- metricCacheMissCount(props) {
269
- return this._api.metricCacheMissCount(props);
270
- }
271
- metricClientError(props) {
272
- return this._api.metricClientError(props);
273
- }
274
- metricCount(props) {
275
- return this._api.metricCount(props);
276
- }
277
- metricIntegrationLatency(props) {
278
- return this._api.metricIntegrationLatency(props);
279
- }
280
- metricLatency(props) {
281
- return this._api.metricLatency(props);
282
- }
283
- metricServerError(props) {
284
- return this._api.metricServerError(props);
285
- }
286
- applyRemovalPolicy(policy) {
287
- this._api.applyRemovalPolicy(policy);
288
- }
289
- }
290
-
291
- class JaypieStack extends cdk$1.Stack {
292
- constructor(scope, id, props = {}) {
293
- const { key, ...stackProps } = props;
294
- // Handle stackName
295
- if (!stackProps.stackName) {
296
- stackProps.stackName = constructStackName(key);
297
- }
298
- // Handle env
299
- stackProps.env = {
300
- account: process.env.CDK_DEFAULT_ACCOUNT,
301
- region: process.env.CDK_DEFAULT_REGION,
302
- ...stackProps.env,
303
- };
304
- super(scope, id, stackProps);
305
- // Apply tags
306
- stackTagger(this, { name: stackProps.stackName });
307
- }
308
- }
309
-
310
- class JaypieAppStack extends JaypieStack {
311
- constructor(scope, id, props = {}) {
312
- const { key = "app", ...stackProps } = props;
313
- // Handle stackName
314
- if (!stackProps.stackName) {
315
- stackProps.stackName = constructStackName(key);
316
- }
317
- super(scope, id, { key, ...stackProps });
318
- }
319
- }
320
-
321
141
  class JaypieLambda extends constructs.Construct {
322
142
  constructor(scope, id, props) {
323
143
  super(scope, id);
324
144
  const { code, datadogApiKeyArn, environment: initialEnvironment = {}, envSecrets = {}, handler = "index.handler", layers = [], logRetention = cdk.CDK.LAMBDA.LOG_RETENTION, memorySize = cdk.CDK.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, provisionedConcurrentExecutions, reservedConcurrentExecutions, roleTag = cdk.CDK.ROLE.PROCESSING, runtime = lambda__namespace.Runtime.NODEJS_22_X, secrets = [], timeout = cdk$1.Duration.seconds(cdk.CDK.DURATION.LAMBDA_WORKER), vendorTag, } = props;
325
145
  // Create a mutable copy of the environment variables
326
146
  let environment = { ...initialEnvironment };
147
+ // Default environment values
148
+ const defaultEnvValues = {
149
+ AWS_LAMBDA_NODEJS_DISABLE_CALLBACK_WARNING: "true",
150
+ };
151
+ // Apply default environment values with user overrides
152
+ Object.entries(defaultEnvValues).forEach(([key, defaultValue]) => {
153
+ if (key in initialEnvironment) {
154
+ const userValue = initialEnvironment[key];
155
+ // If user passes a string, use that value
156
+ if (typeof userValue === "string") {
157
+ environment[key] = userValue;
158
+ }
159
+ // If user passes non-string falsy value, omit the key
160
+ else if (!userValue) {
161
+ delete environment[key];
162
+ }
163
+ // Ignore non-string truthy values (key already not present)
164
+ }
165
+ else {
166
+ // No user override, use default value
167
+ environment[key] = defaultValue;
168
+ }
169
+ });
327
170
  // Default environment variables from process.env if present
328
171
  const defaultEnvVars = [
329
172
  "DATADOG_API_KEY_ARN",
@@ -450,13 +293,13 @@ class JaypieLambda extends constructs.Construct {
450
293
  // Use currentVersion which is auto-published with proper configuration
451
294
  const version = this._lambda.currentVersion;
452
295
  // Create alias for provisioned concurrency
453
- this._alias = new lambda__namespace.Alias(this, "ProvisionedAlias", {
296
+ this._provisioned = new lambda__namespace.Alias(this, "ProvisionedAlias", {
454
297
  aliasName: "provisioned",
455
298
  version,
456
299
  provisionedConcurrentExecutions,
457
300
  });
458
301
  // Add explicit dependencies to ensure proper creation order
459
- this._alias.node.addDependency(version);
302
+ this._provisioned.node.addDependency(version);
460
303
  }
461
304
  if (roleTag) {
462
305
  cdk$1.Tags.of(this._lambda).add(cdk.CDK.TAG.ROLE, roleTag);
@@ -469,18 +312,18 @@ class JaypieLambda extends constructs.Construct {
469
312
  get lambda() {
470
313
  return this._lambda;
471
314
  }
472
- get alias() {
473
- return this._alias;
315
+ get provisioned() {
316
+ return this._provisioned;
474
317
  }
475
318
  get code() {
476
319
  return this._code;
477
320
  }
478
321
  // IFunction implementation
479
322
  get functionArn() {
480
- return this._alias?.functionArn ?? this._lambda.functionArn;
323
+ return this._lambda.functionArn;
481
324
  }
482
325
  get functionName() {
483
- return this._alias?.functionName ?? this._lambda.functionName;
326
+ return this._lambda.functionName;
484
327
  }
485
328
  get grantPrincipal() {
486
329
  return this._lambda.grantPrincipal;
@@ -504,8 +347,7 @@ class JaypieLambda extends constructs.Construct {
504
347
  return this._lambda.permissionsNode;
505
348
  }
506
349
  get resourceArnsForGrantInvoke() {
507
- return (this._alias?.resourceArnsForGrantInvoke ??
508
- this._lambda.resourceArnsForGrantInvoke);
350
+ return this._lambda.resourceArnsForGrantInvoke;
509
351
  }
510
352
  addEventSource(source) {
511
353
  this._lambda.addEventSource(source);
@@ -529,7 +371,7 @@ class JaypieLambda extends constructs.Construct {
529
371
  this._lambda.configureAsyncInvoke(options);
530
372
  }
531
373
  grantInvoke(grantee) {
532
- return (this._alias?.grantInvoke(grantee) ?? this._lambda.grantInvoke(grantee));
374
+ return this._lambda.grantInvoke(grantee);
533
375
  }
534
376
  grantInvokeCompositePrincipal(compositePrincipal) {
535
377
  return this._lambda.grantInvokeCompositePrincipal(compositePrincipal);
@@ -573,6 +415,191 @@ class JaypieLambda extends constructs.Construct {
573
415
  }
574
416
  }
575
417
 
418
+ class JaypieApiGateway extends constructs.Construct {
419
+ constructor(scope, id, props) {
420
+ super(scope, id);
421
+ const { certificate = true, handler, host: propsHost, name, roleTag = cdk.CDK.ROLE.API, zone: propsZone, } = props;
422
+ // Determine zone from props or environment
423
+ let zone = propsZone;
424
+ if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
425
+ zone = process.env.CDK_ENV_API_HOSTED_ZONE;
426
+ }
427
+ // Determine host from props or environment
428
+ let host = propsHost;
429
+ if (!host) {
430
+ if (process.env.CDK_ENV_API_HOST_NAME) {
431
+ host = process.env.CDK_ENV_API_HOST_NAME;
432
+ }
433
+ else if (process.env.CDK_ENV_API_SUBDOMAIN &&
434
+ process.env.CDK_ENV_API_HOSTED_ZONE) {
435
+ host = cdk.mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
436
+ }
437
+ }
438
+ const apiGatewayName = name || constructEnvName("ApiGateway");
439
+ const certificateName = constructEnvName("Certificate");
440
+ const apiDomainName = constructEnvName("ApiDomainName");
441
+ let hostedZone;
442
+ let certificateToUse;
443
+ if (host && zone) {
444
+ if (typeof zone === "string") {
445
+ hostedZone = route53__namespace.HostedZone.fromLookup(this, "HostedZone", {
446
+ domainName: zone,
447
+ });
448
+ }
449
+ else {
450
+ hostedZone = zone;
451
+ }
452
+ if (certificate === true) {
453
+ certificateToUse = new acm__namespace.Certificate(this, certificateName, {
454
+ domainName: host,
455
+ validation: acm__namespace.CertificateValidation.fromDns(hostedZone),
456
+ });
457
+ cdk$1.Tags.of(certificateToUse).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.HOSTING);
458
+ }
459
+ else if (typeof certificate === "object") {
460
+ certificateToUse = certificate;
461
+ }
462
+ this._certificate = certificateToUse;
463
+ this._host = host;
464
+ }
465
+ const {
466
+ // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
467
+ // Ignore the variables we already assigned to other properties
468
+ /* eslint-disable @typescript-eslint/no-unused-vars */
469
+ certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
470
+ /* eslint-enable @typescript-eslint/no-unused-vars */
471
+ ...lambdaRestApiProps } = props;
472
+ // Check if handler is a JaypieLambda instance and use provisioned alias if available
473
+ let handlerToUse = handler;
474
+ if (handler instanceof JaypieLambda && handler.provisioned) {
475
+ handlerToUse = handler.provisioned;
476
+ }
477
+ this._api = new apiGateway__namespace.LambdaRestApi(this, apiGatewayName, {
478
+ handler: handlerToUse,
479
+ ...lambdaRestApiProps,
480
+ });
481
+ cdk$1.Tags.of(this._api).add(cdk.CDK.TAG.ROLE, roleTag);
482
+ if (host && certificateToUse && hostedZone) {
483
+ this._domainName = this._api.addDomainName(apiDomainName, {
484
+ domainName: host,
485
+ certificate: certificateToUse,
486
+ });
487
+ cdk$1.Tags.of(this._domainName).add(cdk.CDK.TAG.ROLE, roleTag);
488
+ const record = new route53__namespace.ARecord(this, "AliasRecord", {
489
+ recordName: host,
490
+ target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.ApiGatewayDomain(this._domainName)),
491
+ zone: hostedZone,
492
+ });
493
+ cdk$1.Tags.of(record).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.NETWORKING);
494
+ }
495
+ }
496
+ get api() {
497
+ return this._api;
498
+ }
499
+ get url() {
500
+ return this._api.url;
501
+ }
502
+ get certificateArn() {
503
+ return this._certificate?.certificateArn;
504
+ }
505
+ get domainName() {
506
+ return this._domainName?.domainName;
507
+ }
508
+ get host() {
509
+ return this._host;
510
+ }
511
+ get restApiId() {
512
+ return this._api.restApiId;
513
+ }
514
+ get restApiName() {
515
+ return this._api.restApiName;
516
+ }
517
+ get restApiRootResourceId() {
518
+ return this._api.restApiRootResourceId;
519
+ }
520
+ get deploymentStage() {
521
+ return this._api.deploymentStage;
522
+ }
523
+ get domainNameAliasDomainName() {
524
+ return this._domainName?.domainNameAliasDomainName;
525
+ }
526
+ get domainNameAliasHostedZoneId() {
527
+ return this._domainName?.domainNameAliasHostedZoneId;
528
+ }
529
+ get root() {
530
+ return this._api.root;
531
+ }
532
+ get env() {
533
+ return {
534
+ account: cdk$1.Stack.of(this).account,
535
+ region: cdk$1.Stack.of(this).region,
536
+ };
537
+ }
538
+ get stack() {
539
+ return this._api.stack;
540
+ }
541
+ arnForExecuteApi(method, path, stage) {
542
+ return this._api.arnForExecuteApi(method, path, stage);
543
+ }
544
+ metric(metricName, props) {
545
+ return this._api.metric(metricName, props);
546
+ }
547
+ metricCacheHitCount(props) {
548
+ return this._api.metricCacheHitCount(props);
549
+ }
550
+ metricCacheMissCount(props) {
551
+ return this._api.metricCacheMissCount(props);
552
+ }
553
+ metricClientError(props) {
554
+ return this._api.metricClientError(props);
555
+ }
556
+ metricCount(props) {
557
+ return this._api.metricCount(props);
558
+ }
559
+ metricIntegrationLatency(props) {
560
+ return this._api.metricIntegrationLatency(props);
561
+ }
562
+ metricLatency(props) {
563
+ return this._api.metricLatency(props);
564
+ }
565
+ metricServerError(props) {
566
+ return this._api.metricServerError(props);
567
+ }
568
+ applyRemovalPolicy(policy) {
569
+ this._api.applyRemovalPolicy(policy);
570
+ }
571
+ }
572
+
573
+ class JaypieStack extends cdk$1.Stack {
574
+ constructor(scope, id, props = {}) {
575
+ const { key, ...stackProps } = props;
576
+ // Handle stackName
577
+ if (!stackProps.stackName) {
578
+ stackProps.stackName = constructStackName(key);
579
+ }
580
+ // Handle env
581
+ stackProps.env = {
582
+ account: process.env.CDK_DEFAULT_ACCOUNT,
583
+ region: process.env.CDK_DEFAULT_REGION,
584
+ ...stackProps.env,
585
+ };
586
+ super(scope, id, stackProps);
587
+ // Apply tags
588
+ stackTagger(this, { name: stackProps.stackName });
589
+ }
590
+ }
591
+
592
+ class JaypieAppStack extends JaypieStack {
593
+ constructor(scope, id, props = {}) {
594
+ const { key = "app", ...stackProps } = props;
595
+ // Handle stackName
596
+ if (!stackProps.stackName) {
597
+ stackProps.stackName = constructStackName(key);
598
+ }
599
+ super(scope, id, { key, ...stackProps });
600
+ }
601
+ }
602
+
576
603
  class JaypieQueuedLambda extends constructs.Construct {
577
604
  constructor(scope, id, props) {
578
605
  super(scope, id);