@jaypie/constructs 1.1.36 → 1.1.38

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.
@@ -1,5 +1,6 @@
1
1
  import { Construct } from "constructs";
2
2
  import { SecretValue, RemovalPolicy, Stack } from "aws-cdk-lib";
3
+ import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
3
4
  import { ISecret, ISecretAttachmentTarget, RotationSchedule, RotationScheduleOptions } from "aws-cdk-lib/aws-secretsmanager";
4
5
  import { IKey } from "aws-cdk-lib/aws-kms";
5
6
  import { Grant, IGrantable, PolicyStatement, AddToResourcePolicyResult } from "aws-cdk-lib/aws-iam";
@@ -7,6 +8,7 @@ export interface JaypieEnvSecretProps {
7
8
  consumer?: boolean;
8
9
  envKey?: string;
9
10
  export?: string;
11
+ generateSecretString?: secretsmanager.SecretStringGenerator;
10
12
  provider?: boolean;
11
13
  roleTag?: string;
12
14
  vendorTag?: string;
@@ -3,20 +3,36 @@ import { Duration, Stack, RemovalPolicy } from "aws-cdk-lib";
3
3
  import * as lambda from "aws-cdk-lib/aws-lambda";
4
4
  import * as iam from "aws-cdk-lib/aws-iam";
5
5
  import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch";
6
+ import * as ec2 from "aws-cdk-lib/aws-ec2";
6
7
  import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
7
8
  import { JaypieEnvSecret } from "./JaypieEnvSecret.js";
8
9
  export interface JaypieLambdaProps {
10
+ allowAllOutbound?: boolean;
11
+ allowPublicSubnet?: boolean;
12
+ architecture?: lambda.Architecture;
9
13
  code: lambda.Code | string;
14
+ codeSigningConfig?: lambda.ICodeSigningConfig;
10
15
  datadogApiKeyArn?: string;
16
+ deadLetterQueue?: import("aws-cdk-lib/aws-sqs").IQueue;
17
+ deadLetterQueueEnabled?: boolean;
18
+ deadLetterTopic?: import("aws-cdk-lib/aws-sns").ITopic;
19
+ description?: string;
11
20
  environment?: {
12
21
  [key: string]: string;
13
22
  };
23
+ environmentEncryption?: import("aws-cdk-lib/aws-kms").IKey;
14
24
  envSecrets?: {
15
25
  [key: string]: secretsmanager.ISecret;
16
26
  };
27
+ ephemeralStorageSize?: import("aws-cdk-lib").Size;
28
+ filesystem?: lambda.FileSystemConfig;
17
29
  handler: string;
30
+ initialPolicy?: iam.PolicyStatement[];
18
31
  layers?: lambda.ILayerVersion[];
19
32
  logRetention?: number;
33
+ logRetentionRole?: iam.IRole;
34
+ logRetentionRetryOptions?: lambda.LogRetentionRetryOptions;
35
+ maxEventAge?: Duration;
20
36
  memorySize?: number;
21
37
  paramsAndSecrets?: lambda.ParamsAndSecretsLayerVersion | boolean;
22
38
  paramsAndSecretsOptions?: {
@@ -25,23 +41,60 @@ export interface JaypieLambdaProps {
25
41
  parameterStoreTtl?: number;
26
42
  secretsManagerTtl?: number;
27
43
  };
44
+ profiling?: boolean;
45
+ profilingGroup?: import("aws-cdk-lib/aws-codeguruprofiler").IProfilingGroup;
28
46
  provisionedConcurrentExecutions?: number;
29
47
  reservedConcurrentExecutions?: number;
48
+ retryAttempts?: number;
30
49
  roleTag?: string;
31
50
  runtime?: lambda.Runtime;
51
+ runtimeManagementMode?: lambda.RuntimeManagementMode;
32
52
  secrets?: JaypieEnvSecret[];
53
+ securityGroups?: ec2.ISecurityGroup[];
33
54
  timeout?: Duration | number;
55
+ tracing?: lambda.Tracing;
34
56
  vendorTag?: string;
57
+ vpc?: ec2.IVpc;
58
+ vpcSubnets?: ec2.SubnetSelection;
35
59
  }
36
60
  export declare class JaypieLambda extends Construct implements lambda.IFunction {
37
61
  private readonly _lambda;
38
62
  private readonly _provisioned?;
39
63
  private readonly _code;
40
64
  private readonly _reference;
65
+ private readonly _handler;
66
+ private readonly _memorySize;
67
+ private readonly _timeout;
68
+ private readonly _runtime;
69
+ private readonly _environment;
70
+ private readonly _vpc?;
71
+ private readonly _vpcSubnets?;
72
+ private readonly _securityGroups?;
73
+ private readonly _reservedConcurrentExecutions?;
74
+ private readonly _layers;
75
+ private readonly _architecture;
76
+ private readonly _ephemeralStorageSize?;
77
+ private readonly _codeSigningConfig?;
78
+ private readonly _filesystemConfigs?;
79
+ private readonly _environmentEncryption?;
80
+ private readonly _tracing?;
81
+ private readonly _profiling?;
82
+ private readonly _profilingGroup?;
83
+ private readonly _logRetentionRole?;
84
+ private readonly _logRetentionRetryOptions?;
85
+ private readonly _initialPolicy?;
86
+ private readonly _description?;
87
+ private readonly _maxEventAge?;
88
+ private readonly _retryAttempts?;
89
+ private readonly _runtimeManagementMode?;
90
+ private readonly _allowAllOutbound?;
91
+ private readonly _allowPublicSubnet?;
92
+ private readonly _deadLetterQueueEnabled?;
41
93
  constructor(scope: Construct, id: string, props: JaypieLambdaProps);
42
94
  get lambda(): lambda.Function;
43
95
  get provisioned(): lambda.Alias | undefined;
44
96
  get code(): lambda.Code;
97
+ get reference(): lambda.IFunction;
45
98
  get functionArn(): string;
46
99
  get functionName(): string;
47
100
  get grantPrincipal(): iam.IPrincipal;
@@ -75,4 +128,47 @@ export declare class JaypieLambda extends Construct implements lambda.IFunction
75
128
  };
76
129
  get stack(): Stack;
77
130
  applyRemovalPolicy(policy: RemovalPolicy): void;
131
+ get currentVersion(): lambda.Version;
132
+ get deadLetterQueue(): import("aws-cdk-lib/aws-sqs").IQueue | undefined;
133
+ get deadLetterTopic(): import("aws-cdk-lib/aws-sns").ITopic | undefined;
134
+ get logGroup(): import("aws-cdk-lib/aws-logs").ILogGroup;
135
+ get runtime(): lambda.Runtime;
136
+ get timeout(): Duration | undefined;
137
+ addAlias(aliasName: string, options?: lambda.AliasOptions): lambda.Alias;
138
+ addLayers(...layers: lambda.ILayerVersion[]): void;
139
+ invalidateVersionBasedOn(x: string): void;
140
+ metricConcurrentExecutions(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
141
+ metricUnreservedConcurrentExecutions(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
142
+ addVersion(name: string, codeSha256?: string, description?: string, provisionedExecutions?: number, asyncInvokeConfig?: lambda.EventInvokeConfigOptions): lambda.Version;
143
+ get memorySize(): number | undefined;
144
+ get handler(): string;
145
+ get environment(): {
146
+ [key: string]: string;
147
+ } | undefined;
148
+ get layers(): lambda.ILayerVersion[] | undefined;
149
+ get maxEventAge(): Duration | undefined;
150
+ get retryAttempts(): number | undefined;
151
+ get reservedConcurrentExecutions(): number | undefined;
152
+ get description(): string | undefined;
153
+ get initialPolicy(): iam.PolicyStatement[] | undefined;
154
+ get logRetentionRole(): iam.IRole | undefined;
155
+ get logRetentionRetryOptions(): lambda.LogRetentionRetryOptions | undefined;
156
+ get tracing(): lambda.Tracing | undefined;
157
+ get profiling(): boolean | undefined;
158
+ get profilingGroup(): import("aws-cdk-lib/aws-codeguruprofiler").IProfilingGroup | undefined;
159
+ get environmentEncryption(): import("aws-cdk-lib/aws-kms").IKey | undefined;
160
+ get codeSigningConfig(): lambda.ICodeSigningConfig | undefined;
161
+ get filesystemConfig(): lambda.FileSystemConfig | undefined;
162
+ get filesystemConfigs(): lambda.FileSystemConfig[] | undefined;
163
+ get ephemeralStorageSize(): number | undefined;
164
+ get runtimeManagementMode(): lambda.RuntimeManagementMode | undefined;
165
+ get architectureLabel(): string;
166
+ get vpc(): ec2.IVpc | undefined;
167
+ get vpcSubnets(): ec2.SubnetSelection | undefined;
168
+ get securityGroups(): ec2.ISecurityGroup[] | undefined;
169
+ get allowAllOutbound(): boolean | undefined;
170
+ get allowPublicSubnet(): boolean | undefined;
171
+ get canCreateLambdaLogGroup(): boolean;
172
+ get canCreatePermissions(): boolean;
173
+ get deadLetterQueueEnabled(): boolean | undefined;
78
174
  }
package/dist/esm/index.js CHANGED
@@ -12,6 +12,7 @@ import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
12
12
  import * as lambda from 'aws-cdk-lib/aws-lambda';
13
13
  import * as sqs from 'aws-cdk-lib/aws-sqs';
14
14
  import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
15
+ import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
15
16
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
16
17
  import { ServicePrincipal, Role, FederatedPrincipal, PolicyStatement, Effect } from 'aws-cdk-lib/aws-iam';
17
18
  import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
@@ -289,7 +290,7 @@ class JaypieAppStack extends JaypieStack {
289
290
  class JaypieLambda extends Construct {
290
291
  constructor(scope, id, props) {
291
292
  super(scope, id);
292
- const { code, datadogApiKeyArn, environment: initialEnvironment = {}, envSecrets = {}, handler = "index.handler", layers = [], logRetention = CDK$2.LAMBDA.LOG_RETENTION, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, provisionedConcurrentExecutions, reservedConcurrentExecutions, roleTag = CDK$2.ROLE.PROCESSING, runtime = lambda.Runtime.NODEJS_22_X, secrets = [], timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), vendorTag, } = props;
293
+ const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, codeSigningConfig, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment: initialEnvironment = {}, environmentEncryption, envSecrets = {}, ephemeralStorageSize, filesystem, handler = "index.handler", initialPolicy, layers = [], logRetention = CDK$2.LAMBDA.LOG_RETENTION, logRetentionRole, logRetentionRetryOptions, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag = CDK$2.ROLE.PROCESSING, runtime = lambda.Runtime.NODEJS_22_X, runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
293
294
  // Create a mutable copy of the environment variables
294
295
  let environment = { ...initialEnvironment };
295
296
  // Default environment values
@@ -403,20 +404,43 @@ class JaypieLambda extends Construct {
403
404
  }, {});
404
405
  // Create Lambda Function
405
406
  this._lambda = new lambda.Function(this, "Function", {
407
+ allowAllOutbound,
408
+ allowPublicSubnet,
409
+ architecture,
406
410
  code: this._code,
411
+ codeSigningConfig,
412
+ deadLetterQueue,
413
+ deadLetterQueueEnabled,
414
+ deadLetterTopic,
415
+ description,
407
416
  environment: {
408
417
  ...environment,
409
418
  ...secretsEnvironment,
410
419
  ...jaypieSecretsEnvironment,
411
420
  },
421
+ environmentEncryption,
422
+ ephemeralStorageSize,
423
+ filesystem: filesystem ? { config: filesystem } : undefined,
412
424
  handler,
425
+ initialPolicy,
413
426
  layers: resolvedLayers,
414
427
  logRetention,
428
+ logRetentionRole,
429
+ logRetentionRetryOptions,
430
+ maxEventAge,
415
431
  memorySize,
416
432
  paramsAndSecrets: resolvedParamsAndSecrets,
433
+ profiling,
434
+ profilingGroup,
417
435
  reservedConcurrentExecutions,
436
+ retryAttempts,
418
437
  runtime,
438
+ runtimeManagementMode,
439
+ securityGroups,
419
440
  timeout: typeof timeout === "number" ? Duration.seconds(timeout) : timeout,
441
+ tracing,
442
+ vpc,
443
+ vpcSubnets,
420
444
  // Enable auto-publishing of versions when using provisioned concurrency
421
445
  currentVersionOptions: provisionedConcurrentExecutions !== undefined
422
446
  ? {
@@ -458,6 +482,40 @@ class JaypieLambda extends Construct {
458
482
  if (vendorTag) {
459
483
  Tags.of(this._lambda).add(CDK$2.TAG.VENDOR, vendorTag);
460
484
  }
485
+ // Store constructor props for later access
486
+ this._handler = handler;
487
+ this._memorySize = memorySize;
488
+ this._timeout =
489
+ typeof timeout === "number" ? Duration.seconds(timeout) : timeout;
490
+ this._runtime = runtime;
491
+ this._environment = {
492
+ ...environment,
493
+ ...secretsEnvironment,
494
+ ...jaypieSecretsEnvironment,
495
+ };
496
+ this._vpc = vpc;
497
+ this._vpcSubnets = vpcSubnets;
498
+ this._securityGroups = securityGroups;
499
+ this._reservedConcurrentExecutions = reservedConcurrentExecutions;
500
+ this._layers = resolvedLayers;
501
+ this._architecture = architecture;
502
+ this._ephemeralStorageSize = ephemeralStorageSize?.toMebibytes();
503
+ this._codeSigningConfig = codeSigningConfig;
504
+ this._filesystemConfigs = filesystem ? [filesystem] : undefined;
505
+ this._environmentEncryption = environmentEncryption;
506
+ this._tracing = tracing;
507
+ this._profiling = profiling;
508
+ this._profilingGroup = profilingGroup;
509
+ this._logRetentionRole = logRetentionRole;
510
+ this._logRetentionRetryOptions = logRetentionRetryOptions;
511
+ this._initialPolicy = initialPolicy;
512
+ this._description = description;
513
+ this._maxEventAge = maxEventAge;
514
+ this._retryAttempts = retryAttempts;
515
+ this._runtimeManagementMode = runtimeManagementMode;
516
+ this._allowAllOutbound = allowAllOutbound;
517
+ this._allowPublicSubnet = allowPublicSubnet;
518
+ this._deadLetterQueueEnabled = deadLetterQueueEnabled;
461
519
  // Assign _reference based on provisioned state
462
520
  this._reference =
463
521
  this._provisioned !== undefined ? this._provisioned : this._lambda;
@@ -472,6 +530,9 @@ class JaypieLambda extends Construct {
472
530
  get code() {
473
531
  return this._code;
474
532
  }
533
+ get reference() {
534
+ return this._reference;
535
+ }
475
536
  // IFunction implementation
476
537
  get functionArn() {
477
538
  return this._reference.functionArn;
@@ -567,6 +628,147 @@ class JaypieLambda extends Construct {
567
628
  applyRemovalPolicy(policy) {
568
629
  this._reference.applyRemovalPolicy(policy);
569
630
  }
631
+ // Additional Lambda Function specific methods
632
+ get currentVersion() {
633
+ return this._lambda.currentVersion;
634
+ }
635
+ get deadLetterQueue() {
636
+ return this._lambda.deadLetterQueue;
637
+ }
638
+ get deadLetterTopic() {
639
+ return this._lambda.deadLetterTopic;
640
+ }
641
+ get logGroup() {
642
+ return this._lambda.logGroup;
643
+ }
644
+ get runtime() {
645
+ return this._runtime;
646
+ }
647
+ get timeout() {
648
+ return this._timeout;
649
+ }
650
+ addAlias(aliasName, options) {
651
+ return this._lambda.addAlias(aliasName, options);
652
+ }
653
+ addLayers(...layers) {
654
+ this._lambda.addLayers(...layers);
655
+ }
656
+ invalidateVersionBasedOn(x) {
657
+ this._lambda.invalidateVersionBasedOn(x);
658
+ }
659
+ metricConcurrentExecutions(props) {
660
+ return new cloudwatch.Metric({
661
+ namespace: "AWS/Lambda",
662
+ metricName: "ConcurrentExecutions",
663
+ dimensionsMap: {
664
+ FunctionName: this.functionName,
665
+ },
666
+ ...props,
667
+ });
668
+ }
669
+ metricUnreservedConcurrentExecutions(props) {
670
+ return new cloudwatch.Metric({
671
+ namespace: "AWS/Lambda",
672
+ metricName: "UnreservedConcurrentExecutions",
673
+ ...props,
674
+ });
675
+ }
676
+ addVersion(name, codeSha256, description, provisionedExecutions, asyncInvokeConfig) {
677
+ return new lambda.Version(this, name, {
678
+ lambda: this._lambda,
679
+ codeSha256,
680
+ description,
681
+ provisionedConcurrentExecutions: provisionedExecutions,
682
+ ...asyncInvokeConfig,
683
+ });
684
+ }
685
+ get memorySize() {
686
+ return this._memorySize;
687
+ }
688
+ get handler() {
689
+ return this._handler;
690
+ }
691
+ get environment() {
692
+ return this._environment;
693
+ }
694
+ get layers() {
695
+ return this._layers;
696
+ }
697
+ get maxEventAge() {
698
+ return this._maxEventAge;
699
+ }
700
+ get retryAttempts() {
701
+ return this._retryAttempts;
702
+ }
703
+ get reservedConcurrentExecutions() {
704
+ return this._reservedConcurrentExecutions;
705
+ }
706
+ get description() {
707
+ return this._description;
708
+ }
709
+ get initialPolicy() {
710
+ return this._initialPolicy;
711
+ }
712
+ get logRetentionRole() {
713
+ return this._logRetentionRole;
714
+ }
715
+ get logRetentionRetryOptions() {
716
+ return this._logRetentionRetryOptions;
717
+ }
718
+ get tracing() {
719
+ return this._tracing;
720
+ }
721
+ get profiling() {
722
+ return this._profiling;
723
+ }
724
+ get profilingGroup() {
725
+ return this._profilingGroup;
726
+ }
727
+ get environmentEncryption() {
728
+ return this._environmentEncryption;
729
+ }
730
+ get codeSigningConfig() {
731
+ return this._codeSigningConfig;
732
+ }
733
+ get filesystemConfig() {
734
+ return this._filesystemConfigs?.[0];
735
+ }
736
+ get filesystemConfigs() {
737
+ return this._filesystemConfigs;
738
+ }
739
+ get ephemeralStorageSize() {
740
+ return this._ephemeralStorageSize;
741
+ }
742
+ get runtimeManagementMode() {
743
+ return this._runtimeManagementMode;
744
+ }
745
+ get architectureLabel() {
746
+ return this._lambda.architecture.name;
747
+ }
748
+ get vpc() {
749
+ return this._vpc;
750
+ }
751
+ get vpcSubnets() {
752
+ return this._vpcSubnets;
753
+ }
754
+ get securityGroups() {
755
+ return this._securityGroups;
756
+ }
757
+ get allowAllOutbound() {
758
+ return this._allowAllOutbound;
759
+ }
760
+ get allowPublicSubnet() {
761
+ return this._allowPublicSubnet;
762
+ }
763
+ get canCreateLambdaLogGroup() {
764
+ return true;
765
+ }
766
+ get canCreatePermissions() {
767
+ return true;
768
+ }
769
+ get deadLetterQueueEnabled() {
770
+ return this._lambda.deadLetterQueue !== undefined || this._lambda.deadLetterTopic !== undefined;
771
+ }
570
772
  }
571
773
 
572
774
  class JaypieQueuedLambda extends Construct {
@@ -989,7 +1191,7 @@ function exportEnvName(name, env = process.env) {
989
1191
  class JaypieEnvSecret extends Construct {
990
1192
  constructor(scope, id, props) {
991
1193
  super(scope, id);
992
- const { consumer = checkEnvIsConsumer(), envKey, export: exportParam, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
1194
+ const { consumer = checkEnvIsConsumer(), envKey, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
993
1195
  this._envKey = envKey;
994
1196
  let exportName;
995
1197
  if (!exportParam) {
@@ -1009,7 +1211,8 @@ class JaypieEnvSecret extends Construct {
1009
1211
  else {
1010
1212
  const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
1011
1213
  const secretProps = {
1012
- secretStringValue: secretValue
1214
+ generateSecretString,
1215
+ secretStringValue: !generateSecretString && secretValue
1013
1216
  ? SecretValue.unsafePlainText(secretValue)
1014
1217
  : undefined,
1015
1218
  };