@jaypie/constructs 1.1.21 → 1.1.23

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/esm/index.js CHANGED
@@ -1,16 +1,607 @@
1
- import { Construct } from 'constructs';
2
1
  import * as cdk from 'aws-cdk-lib';
3
- import { Fn, CfnOutput, SecretValue, Tags, Stack, Duration } from 'aws-cdk-lib';
4
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
2
+ import { Duration, Stack, Tags, RemovalPolicy, Fn, CfnOutput, SecretValue } from 'aws-cdk-lib';
3
+ import * as s3 from 'aws-cdk-lib/aws-s3';
4
+ import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
5
5
  import { CDK } from '@jaypie/cdk';
6
- import { ServicePrincipal } from 'aws-cdk-lib/aws-iam';
7
- import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
8
- import { HostedZone } from 'aws-cdk-lib/aws-route53';
6
+ import { Construct } from 'constructs';
9
7
  import * as lambda from 'aws-cdk-lib/aws-lambda';
10
8
  import * as sqs from 'aws-cdk-lib/aws-sqs';
11
9
  import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
10
+ import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
11
+ import { ServicePrincipal } from 'aws-cdk-lib/aws-iam';
12
+ import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
13
+ import { HostedZone } from 'aws-cdk-lib/aws-route53';
12
14
  import * as sso from 'aws-cdk-lib/aws-sso';
13
15
 
16
+ class JaypieLambda extends Construct {
17
+ constructor(scope, id, props) {
18
+ super(scope, id);
19
+ const { code, datadogApiKeyArn, environment: initialEnvironment = {}, envSecrets = {}, handler = "index.handler", layers = [], logRetention = CDK.LAMBDA.LOG_RETENTION, memorySize = CDK.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, reservedConcurrentExecutions, roleTag, runtime = lambda.Runtime.NODEJS_20_X, secrets = [], timeout = Duration.seconds(CDK.DURATION.LAMBDA_WORKER), vendorTag, } = props;
20
+ // Create a mutable copy of the environment variables
21
+ let environment = { ...initialEnvironment };
22
+ this._code = typeof code === "string" ? lambda.Code.fromAsset(code) : code;
23
+ // Create a working copy of layers
24
+ const resolvedLayers = [...layers];
25
+ // Determine if we should add Datadog integration
26
+ // Check for datadog API key ARN in different sources
27
+ const resolvedDatadogApiKeyArn = datadogApiKeyArn ||
28
+ process.env.DATADOG_API_KEY_ARN ||
29
+ process.env.CDK_ENV_DATADOG_API_KEY_ARN;
30
+ // Add Datadog integration if API key is available
31
+ if (resolvedDatadogApiKeyArn) {
32
+ // Add Datadog Node.js layer
33
+ const datadogNodeLayer = lambda.LayerVersion.fromLayerVersionArn(this, "DatadogNodeLayer", `arn:aws:lambda:${Stack.of(this).region}:464622532012:layer:Datadog-Node20-x:${CDK.DATADOG.LAYER.NODE}`);
34
+ resolvedLayers.push(datadogNodeLayer);
35
+ // Add Datadog Extension layer
36
+ const datadogExtensionLayer = lambda.LayerVersion.fromLayerVersionArn(this, "DatadogExtensionLayer", `arn:aws:lambda:${Stack.of(this).region}:464622532012:layer:Datadog-Extension:${CDK.DATADOG.LAYER.EXTENSION}`);
37
+ resolvedLayers.push(datadogExtensionLayer);
38
+ // Set Datadog environment variables
39
+ Object.assign(environment, {
40
+ DD_API_KEY_SECRET_ARN: resolvedDatadogApiKeyArn,
41
+ DD_ENV: process.env.PROJECT_ENV || "",
42
+ DD_SERVICE: process.env.PROJECT_SERVICE || "",
43
+ DD_SITE: CDK.DATADOG.SITE,
44
+ DD_TAGS: `${CDK.TAG.SPONSOR}:${process.env.PROJECT_SPONSOR || ""}`,
45
+ });
46
+ }
47
+ // Configure ParamsAndSecrets layer
48
+ let resolvedParamsAndSecrets = undefined;
49
+ if (paramsAndSecrets !== false) {
50
+ if (paramsAndSecrets instanceof lambda.ParamsAndSecretsLayerVersion) {
51
+ resolvedParamsAndSecrets = paramsAndSecrets;
52
+ }
53
+ else {
54
+ // Create default ParamsAndSecrets layer
55
+ resolvedParamsAndSecrets =
56
+ lambda.ParamsAndSecretsLayerVersion.fromVersion(lambda.ParamsAndSecretsVersions.V1_0_103, {
57
+ cacheSize: paramsAndSecretsOptions?.cacheSize,
58
+ logLevel: paramsAndSecretsOptions?.logLevel ||
59
+ lambda.ParamsAndSecretsLogLevel.WARN,
60
+ parameterStoreTtl: paramsAndSecretsOptions?.parameterStoreTtl,
61
+ secretsManagerTtl: paramsAndSecretsOptions?.secretsManagerTtl,
62
+ });
63
+ }
64
+ }
65
+ // Process secrets environment variables
66
+ const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
67
+ ...acc,
68
+ [`SECRET_${key}`]: secret.secretName,
69
+ }), {});
70
+ // Process JaypieEnvSecret array
71
+ const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
72
+ if (secret.envKey) {
73
+ return {
74
+ ...acc,
75
+ [`SECRET_${secret.envKey}`]: secret.secretName,
76
+ };
77
+ }
78
+ return acc;
79
+ }, {});
80
+ // Create Lambda Function
81
+ this._lambda = new lambda.Function(this, "Function", {
82
+ code: this._code,
83
+ environment: {
84
+ ...environment,
85
+ ...secretsEnvironment,
86
+ ...jaypieSecretsEnvironment,
87
+ },
88
+ handler,
89
+ layers: resolvedLayers,
90
+ logRetention,
91
+ memorySize,
92
+ paramsAndSecrets: resolvedParamsAndSecrets,
93
+ reservedConcurrentExecutions,
94
+ runtime,
95
+ timeout: typeof timeout === "number" ? Duration.seconds(timeout) : timeout,
96
+ });
97
+ // Grant secret read permissions
98
+ Object.values(envSecrets).forEach((secret) => {
99
+ secret.grantRead(this._lambda);
100
+ });
101
+ // Grant read permissions for JaypieEnvSecrets
102
+ secrets.forEach((secret) => {
103
+ secret.grantRead(this);
104
+ secret.grantRead(this._lambda);
105
+ });
106
+ // Grant Datadog API key read permission if applicable
107
+ if (resolvedDatadogApiKeyArn) {
108
+ const datadogApiKey = secretsmanager.Secret.fromSecretCompleteArn(this, "DatadogApiKeyGrant", resolvedDatadogApiKeyArn);
109
+ datadogApiKey.grantRead(this._lambda);
110
+ }
111
+ if (roleTag) {
112
+ Tags.of(this._lambda).add(CDK.TAG.ROLE, roleTag);
113
+ }
114
+ if (vendorTag) {
115
+ Tags.of(this._lambda).add(CDK.TAG.VENDOR, vendorTag);
116
+ }
117
+ }
118
+ // Public accessors
119
+ get lambda() {
120
+ return this._lambda;
121
+ }
122
+ get code() {
123
+ return this._code;
124
+ }
125
+ // IFunction implementation
126
+ get functionArn() {
127
+ return this._lambda.functionArn;
128
+ }
129
+ get functionName() {
130
+ return this._lambda.functionName;
131
+ }
132
+ get grantPrincipal() {
133
+ return this._lambda.grantPrincipal;
134
+ }
135
+ get role() {
136
+ return this._lambda.role;
137
+ }
138
+ get architecture() {
139
+ return this._lambda.architecture;
140
+ }
141
+ get connections() {
142
+ return this._lambda.connections;
143
+ }
144
+ get isBoundToVpc() {
145
+ return this._lambda.isBoundToVpc;
146
+ }
147
+ get latestVersion() {
148
+ return this._lambda.latestVersion;
149
+ }
150
+ get permissionsNode() {
151
+ return this._lambda.permissionsNode;
152
+ }
153
+ get resourceArnsForGrantInvoke() {
154
+ return this._lambda.resourceArnsForGrantInvoke;
155
+ }
156
+ addEventSource(source) {
157
+ this._lambda.addEventSource(source);
158
+ }
159
+ addEventSourceMapping(id, options) {
160
+ return this._lambda.addEventSourceMapping(id, options);
161
+ }
162
+ addFunctionUrl(options) {
163
+ return this._lambda.addFunctionUrl(options);
164
+ }
165
+ addPermission(id, permission) {
166
+ this._lambda.addPermission(id, permission);
167
+ }
168
+ addToRolePolicy(statement) {
169
+ this._lambda.addToRolePolicy(statement);
170
+ }
171
+ configureAsyncInvoke(options) {
172
+ this._lambda.configureAsyncInvoke(options);
173
+ }
174
+ grantInvoke(grantee) {
175
+ return this._lambda.grantInvoke(grantee);
176
+ }
177
+ grantInvokeCompositePrincipal(compositePrincipal) {
178
+ return this._lambda.grantInvokeCompositePrincipal(compositePrincipal);
179
+ }
180
+ grantInvokeUrl(grantee) {
181
+ return this._lambda.grantInvokeUrl(grantee);
182
+ }
183
+ metric(metricName, props) {
184
+ return this._lambda.metric(metricName, props);
185
+ }
186
+ metricDuration(props) {
187
+ return this._lambda.metricDuration(props);
188
+ }
189
+ metricErrors(props) {
190
+ return this._lambda.metricErrors(props);
191
+ }
192
+ metricInvocations(props) {
193
+ return this._lambda.metricInvocations(props);
194
+ }
195
+ metricThrottles(props) {
196
+ return this._lambda.metricThrottles(props);
197
+ }
198
+ // Additional IFunction implementation
199
+ grantInvokeLatestVersion(grantee) {
200
+ return this._lambda.grantInvokeLatestVersion(grantee);
201
+ }
202
+ grantInvokeVersion(grantee, version) {
203
+ return this._lambda.grantInvokeVersion(grantee, version);
204
+ }
205
+ get env() {
206
+ return {
207
+ account: Stack.of(this).account,
208
+ region: Stack.of(this).region,
209
+ };
210
+ }
211
+ get stack() {
212
+ return this._lambda.stack;
213
+ }
214
+ applyRemovalPolicy(policy) {
215
+ this._lambda.applyRemovalPolicy(policy);
216
+ }
217
+ }
218
+
219
+ class JaypieQueuedLambda extends Construct {
220
+ constructor(scope, id, props) {
221
+ super(scope, id);
222
+ const { batchSize = 1, code, environment = {}, envSecrets = {}, fifo = true, handler = "index.handler", layers = [], logRetention = CDK.LAMBDA.LOG_RETENTION, memorySize = CDK.LAMBDA.MEMORY_SIZE, paramsAndSecrets, reservedConcurrentExecutions, roleTag, runtime = lambda.Runtime.NODEJS_20_X, secrets = [], timeout = Duration.seconds(CDK.DURATION.LAMBDA_WORKER), vendorTag, visibilityTimeout = Duration.seconds(CDK.DURATION.LAMBDA_WORKER), } = props;
223
+ // Create SQS Queue
224
+ this._queue = new sqs.Queue(this, "Queue", {
225
+ fifo,
226
+ visibilityTimeout: typeof visibilityTimeout === "number"
227
+ ? Duration.seconds(visibilityTimeout)
228
+ : visibilityTimeout,
229
+ });
230
+ if (roleTag) {
231
+ Tags.of(this._queue).add(CDK.TAG.ROLE, roleTag);
232
+ }
233
+ if (vendorTag) {
234
+ Tags.of(this._queue).add(CDK.TAG.VENDOR, vendorTag);
235
+ }
236
+ // Create Lambda with JaypieLambda
237
+ this._lambdaConstruct = new JaypieLambda(this, "Function", {
238
+ code,
239
+ environment: {
240
+ ...environment,
241
+ CDK_ENV_QUEUE_URL: this._queue.queueUrl,
242
+ },
243
+ envSecrets,
244
+ handler,
245
+ layers,
246
+ logRetention,
247
+ memorySize,
248
+ paramsAndSecrets,
249
+ reservedConcurrentExecutions,
250
+ roleTag,
251
+ runtime,
252
+ secrets,
253
+ timeout,
254
+ vendorTag,
255
+ });
256
+ // Set up queue and lambda integration
257
+ this._queue.grantConsumeMessages(this._lambdaConstruct);
258
+ this._queue.grantSendMessages(this._lambdaConstruct);
259
+ this._lambdaConstruct.addEventSource(new lambdaEventSources.SqsEventSource(this._queue, {
260
+ batchSize,
261
+ }));
262
+ }
263
+ // Public accessors
264
+ get queue() {
265
+ return this._queue;
266
+ }
267
+ get lambda() {
268
+ return this._lambdaConstruct.lambda;
269
+ }
270
+ get code() {
271
+ return this._lambdaConstruct.code;
272
+ }
273
+ // IFunction implementation
274
+ get functionArn() {
275
+ return this._lambdaConstruct.functionArn;
276
+ }
277
+ get functionName() {
278
+ return this._lambdaConstruct.functionName;
279
+ }
280
+ get grantPrincipal() {
281
+ return this._lambdaConstruct.grantPrincipal;
282
+ }
283
+ get role() {
284
+ return this._lambdaConstruct.role;
285
+ }
286
+ get architecture() {
287
+ return this._lambdaConstruct.architecture;
288
+ }
289
+ get connections() {
290
+ return this._lambdaConstruct.connections;
291
+ }
292
+ get isBoundToVpc() {
293
+ return this._lambdaConstruct.isBoundToVpc;
294
+ }
295
+ get latestVersion() {
296
+ return this._lambdaConstruct.latestVersion;
297
+ }
298
+ get permissionsNode() {
299
+ return this._lambdaConstruct.permissionsNode;
300
+ }
301
+ get resourceArnsForGrantInvoke() {
302
+ return this._lambdaConstruct.resourceArnsForGrantInvoke;
303
+ }
304
+ addEventSource(source) {
305
+ this._lambdaConstruct.addEventSource(source);
306
+ }
307
+ addEventSourceMapping(id, options) {
308
+ return this._lambdaConstruct.addEventSourceMapping(id, options);
309
+ }
310
+ addFunctionUrl(options) {
311
+ return this._lambdaConstruct.addFunctionUrl(options);
312
+ }
313
+ addPermission(id, permission) {
314
+ this._lambdaConstruct.addPermission(id, permission);
315
+ }
316
+ addToRolePolicy(statement) {
317
+ this._lambdaConstruct.addToRolePolicy(statement);
318
+ }
319
+ configureAsyncInvoke(options) {
320
+ this._lambdaConstruct.configureAsyncInvoke(options);
321
+ }
322
+ grantInvoke(grantee) {
323
+ return this._lambdaConstruct.grantInvoke(grantee);
324
+ }
325
+ grantInvokeCompositePrincipal(compositePrincipal) {
326
+ return this._lambdaConstruct.grantInvokeCompositePrincipal(compositePrincipal);
327
+ }
328
+ grantInvokeUrl(grantee) {
329
+ return this._lambdaConstruct.grantInvokeUrl(grantee);
330
+ }
331
+ metric(metricName, props) {
332
+ return this._lambdaConstruct.metric(metricName, props);
333
+ }
334
+ metricDuration(props) {
335
+ return this._lambdaConstruct.metricDuration(props);
336
+ }
337
+ metricErrors(props) {
338
+ return this._lambdaConstruct.metricErrors(props);
339
+ }
340
+ metricInvocations(props) {
341
+ return this._lambdaConstruct.metricInvocations(props);
342
+ }
343
+ metricThrottles(props) {
344
+ return this._lambdaConstruct.metricThrottles(props);
345
+ }
346
+ // Additional IFunction implementation
347
+ grantInvokeLatestVersion(grantee) {
348
+ return this._lambdaConstruct.grantInvokeLatestVersion(grantee);
349
+ }
350
+ grantInvokeVersion(grantee, version) {
351
+ return this._lambdaConstruct.grantInvokeVersion(grantee, version);
352
+ }
353
+ get env() {
354
+ return {
355
+ account: Stack.of(this).account,
356
+ region: Stack.of(this).region,
357
+ };
358
+ }
359
+ get stack() {
360
+ return Stack.of(this);
361
+ }
362
+ applyRemovalPolicy(policy) {
363
+ this._lambdaConstruct.applyRemovalPolicy(policy);
364
+ this._queue.applyRemovalPolicy(policy);
365
+ }
366
+ // IQueue implementation
367
+ get fifo() {
368
+ return this._queue.fifo;
369
+ }
370
+ get queueArn() {
371
+ return this._queue.queueArn;
372
+ }
373
+ get queueName() {
374
+ return this._queue.queueName;
375
+ }
376
+ get queueUrl() {
377
+ return this._queue.queueUrl;
378
+ }
379
+ get encryptionMasterKey() {
380
+ return this._queue.encryptionMasterKey;
381
+ }
382
+ addToResourcePolicy(statement) {
383
+ return this._queue.addToResourcePolicy(statement);
384
+ }
385
+ grant(grantee, ...actions) {
386
+ return this._queue.grant(grantee, ...actions);
387
+ }
388
+ grantConsumeMessages(grantee) {
389
+ return this._queue.grantConsumeMessages(grantee);
390
+ }
391
+ grantPurge(grantee) {
392
+ return this._queue.grantPurge(grantee);
393
+ }
394
+ grantSendMessages(grantee) {
395
+ return this._queue.grantSendMessages(grantee);
396
+ }
397
+ // Queue metrics
398
+ metricApproximateAgeOfOldestMessage(props) {
399
+ return this._queue.metricApproximateAgeOfOldestMessage(props);
400
+ }
401
+ metricApproximateNumberOfMessagesDelayed(props) {
402
+ return this._queue.metricApproximateNumberOfMessagesDelayed(props);
403
+ }
404
+ metricApproximateNumberOfMessagesNotVisible(props) {
405
+ return this._queue.metricApproximateNumberOfMessagesNotVisible(props);
406
+ }
407
+ metricApproximateNumberOfMessagesVisible(props) {
408
+ return this._queue.metricApproximateNumberOfMessagesVisible(props);
409
+ }
410
+ metricNumberOfEmptyReceives(props) {
411
+ return this._queue.metricNumberOfEmptyReceives(props);
412
+ }
413
+ metricNumberOfMessagesDeleted(props) {
414
+ return this._queue.metricNumberOfMessagesDeleted(props);
415
+ }
416
+ metricNumberOfMessagesReceived(props) {
417
+ return this._queue.metricNumberOfMessagesReceived(props);
418
+ }
419
+ metricNumberOfMessagesSent(props) {
420
+ return this._queue.metricNumberOfMessagesSent(props);
421
+ }
422
+ metricSentMessageSize(props) {
423
+ return this._queue.metricSentMessageSize(props);
424
+ }
425
+ }
426
+
427
+ class JaypieBucketQueuedLambda extends JaypieQueuedLambda {
428
+ constructor(scope, id, props) {
429
+ super(scope, id, props);
430
+ const { bucketName, roleTag, vendorTag, bucketOptions = {} } = props;
431
+ // Create S3 Bucket
432
+ this._bucket = new s3.Bucket(this, "Bucket", {
433
+ bucketName: bucketOptions.bucketName || bucketName,
434
+ removalPolicy: bucketOptions.removalPolicy || RemovalPolicy.RETAIN,
435
+ ...bucketOptions,
436
+ });
437
+ // Add tags to bucket
438
+ if (roleTag) {
439
+ Tags.of(this._bucket).add(CDK.TAG.ROLE, roleTag);
440
+ }
441
+ if (vendorTag) {
442
+ Tags.of(this._bucket).add(CDK.TAG.VENDOR, vendorTag);
443
+ }
444
+ // Add an event notification from the bucket to the queue
445
+ this._bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(this.queue));
446
+ // Grant the lambda access to the bucket
447
+ this._bucket.grantReadWrite(this);
448
+ // Add environment variable for bucket name
449
+ this.lambda.addEnvironment("CDK_ENV_BUCKET_NAME", this._bucket.bucketName);
450
+ }
451
+ // Public accessors
452
+ get bucket() {
453
+ return this._bucket;
454
+ }
455
+ // IBucket implementation
456
+ get bucketArn() {
457
+ return this._bucket.bucketArn;
458
+ }
459
+ get bucketDomainName() {
460
+ return this._bucket.bucketDomainName;
461
+ }
462
+ get bucketDualStackDomainName() {
463
+ return this._bucket.bucketDualStackDomainName;
464
+ }
465
+ get bucketName() {
466
+ return this._bucket.bucketName;
467
+ }
468
+ get bucketRegionalDomainName() {
469
+ return this._bucket.bucketRegionalDomainName;
470
+ }
471
+ get bucketWebsiteDomainName() {
472
+ return this._bucket.bucketWebsiteDomainName;
473
+ }
474
+ get bucketWebsiteUrl() {
475
+ return this._bucket.bucketWebsiteUrl;
476
+ }
477
+ get encryptionKey() {
478
+ return this._bucket.encryptionKey;
479
+ }
480
+ get isWebsite() {
481
+ return this._bucket.isWebsite || false;
482
+ }
483
+ get policy() {
484
+ return this._bucket.policy;
485
+ }
486
+ addEventNotification(event, dest, filters) {
487
+ this._bucket.addEventNotification(event, dest, ...filters);
488
+ }
489
+ addObjectCreatedNotification(dest, ...filters) {
490
+ this._bucket.addObjectCreatedNotification(dest, ...filters);
491
+ }
492
+ addObjectRemovedNotification(dest, ...filters) {
493
+ this._bucket.addObjectRemovedNotification(dest, ...filters);
494
+ }
495
+ addToResourcePolicy(permission) {
496
+ return this._bucket.addToResourcePolicy(permission);
497
+ }
498
+ arnForObjects(objectKeyPattern) {
499
+ return this._bucket.arnForObjects(objectKeyPattern);
500
+ }
501
+ enableEventBridgeNotification() {
502
+ this._bucket.enableEventBridgeNotification();
503
+ }
504
+ grant(grantee, ...actions) {
505
+ return this._bucket.grant(grantee, ...actions);
506
+ }
507
+ grantDelete(grantee, objectsKeyPattern) {
508
+ return this._bucket.grantDelete(grantee, objectsKeyPattern);
509
+ }
510
+ grantPublicAccess(keyPrefix, ...allowedActions) {
511
+ return this._bucket.grantPublicAccess(keyPrefix, ...allowedActions);
512
+ }
513
+ grantPut(grantee, objectsKeyPattern) {
514
+ return this._bucket.grantPut(grantee, objectsKeyPattern);
515
+ }
516
+ grantPutAcl(grantee, objectsKeyPattern) {
517
+ return this._bucket.grantPutAcl(grantee, objectsKeyPattern);
518
+ }
519
+ grantRead(grantee, objectsKeyPattern) {
520
+ return this._bucket.grantRead(grantee, objectsKeyPattern);
521
+ }
522
+ grantReadWrite(grantee, objectsKeyPattern) {
523
+ return this._bucket.grantReadWrite(grantee, objectsKeyPattern);
524
+ }
525
+ grantWrite(grantee, objectsKeyPattern) {
526
+ return this._bucket.grantWrite(grantee, objectsKeyPattern);
527
+ }
528
+ onCloudTrailEvent(id, options) {
529
+ return this._bucket.onCloudTrailEvent(id, options);
530
+ }
531
+ onCloudTrailPutObject(id, options) {
532
+ return this._bucket.onCloudTrailPutObject(id, options);
533
+ }
534
+ onCloudTrailWriteObject(id, options) {
535
+ return this._bucket.onCloudTrailWriteObject(id, options);
536
+ }
537
+ s3UrlForObject(key) {
538
+ return this._bucket.s3UrlForObject(key);
539
+ }
540
+ transferAccelerationUrlForObject(key, options) {
541
+ return this._bucket.transferAccelerationUrlForObject(key, options);
542
+ }
543
+ urlForObject(key) {
544
+ return this._bucket.urlForObject(key);
545
+ }
546
+ virtualHostedUrlForObject(key, options) {
547
+ return this._bucket.virtualHostedUrlForObject(key, options);
548
+ }
549
+ // Bucket metrics
550
+ metricAllRequests(props) {
551
+ return this._bucket.metricAllRequests(props);
552
+ }
553
+ metricBucketSizeBytes(props) {
554
+ return this._bucket.metricBucketSizeBytes(props);
555
+ }
556
+ metricDeleteRequests(props) {
557
+ return this._bucket.metricDeleteRequests(props);
558
+ }
559
+ metricDownloadBytes(props) {
560
+ return this._bucket.metricDownloadBytes(props);
561
+ }
562
+ metricFirstByteLatency(props) {
563
+ return this._bucket.metricFirstByteLatency(props);
564
+ }
565
+ metricGetRequests(props) {
566
+ return this._bucket.metricGetRequests(props);
567
+ }
568
+ metricHeadRequests(props) {
569
+ return this._bucket.metricHeadRequests(props);
570
+ }
571
+ metricHttpRequests(props) {
572
+ return this._bucket.metricHttpRequests(props);
573
+ }
574
+ metricListRequests(props) {
575
+ return this._bucket.metricListRequests(props);
576
+ }
577
+ metricNumberOfObjects(props) {
578
+ return this._bucket.metricNumberOfObjects(props);
579
+ }
580
+ metricPostRequests(props) {
581
+ return this._bucket.metricPostRequests(props);
582
+ }
583
+ metricPutRequests(props) {
584
+ return this._bucket.metricPutRequests(props);
585
+ }
586
+ metricSelectRequests(props) {
587
+ return this._bucket.metricSelectRequests(props);
588
+ }
589
+ metricSelectScannedBytes(props) {
590
+ return this._bucket.metricSelectScannedBytes(props);
591
+ }
592
+ metricUploadBytes(props) {
593
+ return this._bucket.metricUploadBytes(props);
594
+ }
595
+ metricSelectReturnedBytes(props) {
596
+ return this._bucket.metricSelectReturnedBytes(props);
597
+ }
598
+ // Override applyRemovalPolicy to apply to all resources
599
+ applyRemovalPolicy(policy) {
600
+ super.applyRemovalPolicy(policy);
601
+ this._bucket.applyRemovalPolicy(policy);
602
+ }
603
+ }
604
+
14
605
  // It is a consumer if the environment is ephemeral
15
606
  function checkEnvIsConsumer(env = process.env) {
16
607
  return (env.PROJECT_ENV === CDK.ENV.PERSONAL ||
@@ -214,242 +805,6 @@ class JaypieOpenAiSecret extends JaypieEnvSecret {
214
805
  }
215
806
  }
216
807
 
217
- class JaypieQueuedLambda extends Construct {
218
- constructor(scope, id, props) {
219
- super(scope, id);
220
- const { batchSize = 1, code, environment = {}, envSecrets = {}, fifo = true, handler = "index.handler", layers = [], logRetention = CDK.LAMBDA.LOG_RETENTION, memorySize = CDK.LAMBDA.MEMORY_SIZE, paramsAndSecrets, reservedConcurrentExecutions, roleTag, runtime = lambda.Runtime.NODEJS_20_X, secrets = [], timeout = Duration.seconds(CDK.DURATION.LAMBDA_WORKER), vendorTag, visibilityTimeout = Duration.seconds(CDK.DURATION.LAMBDA_WORKER), } = props;
221
- this._code = typeof code === "string" ? lambda.Code.fromAsset(code) : code;
222
- // Create SQS Queue
223
- this._queue = new sqs.Queue(this, "Queue", {
224
- fifo,
225
- visibilityTimeout: typeof visibilityTimeout === "number"
226
- ? Duration.seconds(visibilityTimeout)
227
- : visibilityTimeout,
228
- });
229
- if (roleTag) {
230
- Tags.of(this._queue).add(CDK.TAG.ROLE, roleTag);
231
- }
232
- if (vendorTag) {
233
- Tags.of(this._queue).add(CDK.TAG.VENDOR, vendorTag);
234
- }
235
- // Process secrets environment variables
236
- const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
237
- ...acc,
238
- [`SECRET_${key}`]: secret.secretName,
239
- }), {});
240
- // Process JaypieEnvSecret array
241
- const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
242
- if (secret.envKey) {
243
- return {
244
- ...acc,
245
- [`SECRET_${secret.envKey}`]: secret.secretName,
246
- };
247
- }
248
- return acc;
249
- }, {});
250
- // Create Lambda Function
251
- this._lambda = new lambda.Function(this, "Function", {
252
- code: this._code,
253
- environment: {
254
- CDK_ENV_QUEUE_URL: this._queue.queueUrl,
255
- ...environment,
256
- ...secretsEnvironment,
257
- ...jaypieSecretsEnvironment,
258
- },
259
- handler,
260
- layers,
261
- logRetention,
262
- memorySize,
263
- paramsAndSecrets,
264
- reservedConcurrentExecutions,
265
- runtime,
266
- timeout: typeof timeout === "number" ? Duration.seconds(timeout) : timeout,
267
- });
268
- // Grant secret read permissions
269
- Object.values(envSecrets).forEach((secret) => {
270
- secret.grantRead(this._lambda);
271
- });
272
- // Grant read permissions for JaypieEnvSecrets
273
- secrets.forEach((secret) => {
274
- secret.grantRead(this);
275
- secret.grantRead(this._lambda);
276
- });
277
- this._queue.grantConsumeMessages(this._lambda);
278
- this._queue.grantSendMessages(this._lambda);
279
- this._lambda.addEventSource(new lambdaEventSources.SqsEventSource(this._queue, {
280
- batchSize,
281
- }));
282
- if (roleTag) {
283
- Tags.of(this._lambda).add(CDK.TAG.ROLE, roleTag);
284
- }
285
- if (vendorTag) {
286
- Tags.of(this._lambda).add(CDK.TAG.VENDOR, vendorTag);
287
- }
288
- }
289
- // Public accessors
290
- get queue() {
291
- return this._queue;
292
- }
293
- get lambda() {
294
- return this._lambda;
295
- }
296
- get code() {
297
- return this._code;
298
- }
299
- // IFunction implementation
300
- get functionArn() {
301
- return this._lambda.functionArn;
302
- }
303
- get functionName() {
304
- return this._lambda.functionName;
305
- }
306
- get grantPrincipal() {
307
- return this._lambda.grantPrincipal;
308
- }
309
- get role() {
310
- return this._lambda.role;
311
- }
312
- get architecture() {
313
- return this._lambda.architecture;
314
- }
315
- get connections() {
316
- return this._lambda.connections;
317
- }
318
- get isBoundToVpc() {
319
- return this._lambda.isBoundToVpc;
320
- }
321
- get latestVersion() {
322
- return this._lambda.latestVersion;
323
- }
324
- get permissionsNode() {
325
- return this._lambda.permissionsNode;
326
- }
327
- get resourceArnsForGrantInvoke() {
328
- return this._lambda.resourceArnsForGrantInvoke;
329
- }
330
- addEventSource(source) {
331
- this._lambda.addEventSource(source);
332
- }
333
- addEventSourceMapping(id, options) {
334
- return this._lambda.addEventSourceMapping(id, options);
335
- }
336
- addFunctionUrl(options) {
337
- return this._lambda.addFunctionUrl(options);
338
- }
339
- addPermission(id, permission) {
340
- this._lambda.addPermission(id, permission);
341
- }
342
- addToRolePolicy(statement) {
343
- this._lambda.addToRolePolicy(statement);
344
- }
345
- configureAsyncInvoke(options) {
346
- this._lambda.configureAsyncInvoke(options);
347
- }
348
- grantInvoke(grantee) {
349
- return this._lambda.grantInvoke(grantee);
350
- }
351
- grantInvokeCompositePrincipal(compositePrincipal) {
352
- return this._lambda.grantInvokeCompositePrincipal(compositePrincipal);
353
- }
354
- grantInvokeUrl(grantee) {
355
- return this._lambda.grantInvokeUrl(grantee);
356
- }
357
- metric(metricName, props) {
358
- return this._lambda.metric(metricName, props);
359
- }
360
- metricDuration(props) {
361
- return this._lambda.metricDuration(props);
362
- }
363
- metricErrors(props) {
364
- return this._lambda.metricErrors(props);
365
- }
366
- metricInvocations(props) {
367
- return this._lambda.metricInvocations(props);
368
- }
369
- metricThrottles(props) {
370
- return this._lambda.metricThrottles(props);
371
- }
372
- // Additional IFunction implementation
373
- grantInvokeLatestVersion(grantee) {
374
- return this._lambda.grantInvokeLatestVersion(grantee);
375
- }
376
- grantInvokeVersion(grantee, version) {
377
- return this._lambda.grantInvokeVersion(grantee, version);
378
- }
379
- get env() {
380
- return {
381
- account: Stack.of(this).account,
382
- region: Stack.of(this).region,
383
- };
384
- }
385
- get stack() {
386
- return this._lambda.stack;
387
- }
388
- applyRemovalPolicy(policy) {
389
- this._lambda.applyRemovalPolicy(policy);
390
- this._queue.applyRemovalPolicy(policy);
391
- }
392
- // IQueue implementation
393
- get fifo() {
394
- return this._queue.fifo;
395
- }
396
- get queueArn() {
397
- return this._queue.queueArn;
398
- }
399
- get queueName() {
400
- return this._queue.queueName;
401
- }
402
- get queueUrl() {
403
- return this._queue.queueUrl;
404
- }
405
- get encryptionMasterKey() {
406
- return this._queue.encryptionMasterKey;
407
- }
408
- addToResourcePolicy(statement) {
409
- return this._queue.addToResourcePolicy(statement);
410
- }
411
- grant(grantee, ...actions) {
412
- return this._queue.grant(grantee, ...actions);
413
- }
414
- grantConsumeMessages(grantee) {
415
- return this._queue.grantConsumeMessages(grantee);
416
- }
417
- grantPurge(grantee) {
418
- return this._queue.grantPurge(grantee);
419
- }
420
- grantSendMessages(grantee) {
421
- return this._queue.grantSendMessages(grantee);
422
- }
423
- // Queue metrics
424
- metricApproximateAgeOfOldestMessage(props) {
425
- return this._queue.metricApproximateAgeOfOldestMessage(props);
426
- }
427
- metricApproximateNumberOfMessagesDelayed(props) {
428
- return this._queue.metricApproximateNumberOfMessagesDelayed(props);
429
- }
430
- metricApproximateNumberOfMessagesNotVisible(props) {
431
- return this._queue.metricApproximateNumberOfMessagesNotVisible(props);
432
- }
433
- metricApproximateNumberOfMessagesVisible(props) {
434
- return this._queue.metricApproximateNumberOfMessagesVisible(props);
435
- }
436
- metricNumberOfEmptyReceives(props) {
437
- return this._queue.metricNumberOfEmptyReceives(props);
438
- }
439
- metricNumberOfMessagesDeleted(props) {
440
- return this._queue.metricNumberOfMessagesDeleted(props);
441
- }
442
- metricNumberOfMessagesReceived(props) {
443
- return this._queue.metricNumberOfMessagesReceived(props);
444
- }
445
- metricNumberOfMessagesSent(props) {
446
- return this._queue.metricNumberOfMessagesSent(props);
447
- }
448
- metricSentMessageSize(props) {
449
- return this._queue.metricSentMessageSize(props);
450
- }
451
- }
452
-
453
808
  /**
454
809
  * Permission set types with corresponding AWS managed policies
455
810
  */
@@ -736,5 +1091,5 @@ class JaypieTraceSigningKeySecret extends JaypieEnvSecret {
736
1091
  }
737
1092
  }
738
1093
 
739
- export { JaypieEnvSecret, JaypieHostedZone, JaypieMongoDbSecret, JaypieOpenAiSecret, JaypieQueuedLambda, JaypieSsoGroups, JaypieTraceSigningKeySecret, PermissionSetType };
1094
+ export { JaypieBucketQueuedLambda, JaypieEnvSecret, JaypieHostedZone, JaypieLambda, JaypieMongoDbSecret, JaypieOpenAiSecret, JaypieQueuedLambda, JaypieSsoGroups, JaypieTraceSigningKeySecret, PermissionSetType };
740
1095
  //# sourceMappingURL=index.js.map