@jaypie/constructs 1.2.11 → 1.2.12
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.
|
@@ -6,7 +6,7 @@ import * as route53 from "aws-cdk-lib/aws-route53";
|
|
|
6
6
|
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
7
7
|
import { LambdaDestination } from "aws-cdk-lib/aws-s3-notifications";
|
|
8
8
|
import { Construct } from "constructs";
|
|
9
|
-
export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior"> {
|
|
9
|
+
export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior" | "logBucket"> {
|
|
10
10
|
/**
|
|
11
11
|
* SSL certificate for the CloudFront distribution
|
|
12
12
|
* @default true (creates a new certificate)
|
|
@@ -20,10 +20,21 @@ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionPro
|
|
|
20
20
|
* Log destination configuration for CloudFront access logs
|
|
21
21
|
* - LambdaDestination: Use a specific Lambda destination for S3 notifications
|
|
22
22
|
* - true: Use Datadog forwarder for S3 notifications (default)
|
|
23
|
-
* - false: Disable logging
|
|
23
|
+
* - false: Disable S3 notifications (logging still occurs if logBucket is set)
|
|
24
24
|
* @default true
|
|
25
25
|
*/
|
|
26
26
|
destination?: LambdaDestination | boolean;
|
|
27
|
+
/**
|
|
28
|
+
* External log bucket for CloudFront access logs.
|
|
29
|
+
* - IBucket: Use existing bucket directly
|
|
30
|
+
* - string: Bucket name to import
|
|
31
|
+
* - { exportName: string }: CloudFormation export name to import
|
|
32
|
+
* - true: Use account logging bucket (CDK.IMPORT.LOG_BUCKET)
|
|
33
|
+
* @default undefined (creates new bucket if destination !== false)
|
|
34
|
+
*/
|
|
35
|
+
logBucket?: s3.IBucket | string | {
|
|
36
|
+
exportName: string;
|
|
37
|
+
} | true;
|
|
27
38
|
/**
|
|
28
39
|
* The origin handler - can be an IOrigin, IFunctionUrl, or IFunction
|
|
29
40
|
* If IFunction, a FunctionUrl will be created with auth NONE
|
|
@@ -74,6 +85,8 @@ export declare class JaypieDistribution extends Construct implements cloudfront.
|
|
|
74
85
|
private isIFunctionUrl;
|
|
75
86
|
private isIFunction;
|
|
76
87
|
private hasInvokeMode;
|
|
88
|
+
private isExportNameObject;
|
|
89
|
+
private resolveLogBucket;
|
|
77
90
|
get env(): {
|
|
78
91
|
account: string;
|
|
79
92
|
region: string;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2357,7 +2357,7 @@ class JaypieDatadogSecret extends JaypieEnvSecret {
|
|
|
2357
2357
|
class JaypieDistribution extends constructs.Construct {
|
|
2358
2358
|
constructor(scope, id, props) {
|
|
2359
2359
|
super(scope, id);
|
|
2360
|
-
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda__namespace.InvokeMode.BUFFERED, originReadTimeout = cdk.Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
2360
|
+
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda__namespace.InvokeMode.BUFFERED, logBucket: logBucketProp, originReadTimeout = cdk.Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
2361
2361
|
// Validate environment variables
|
|
2362
2362
|
if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
2363
2363
|
!isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
|
|
@@ -2459,12 +2459,16 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
2459
2459
|
});
|
|
2460
2460
|
this.certificate = certificateToUse;
|
|
2461
2461
|
}
|
|
2462
|
-
//
|
|
2462
|
+
// Resolve or create log bucket
|
|
2463
2463
|
let logBucket;
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2464
|
+
const isExternalBucket = logBucketProp !== undefined;
|
|
2465
|
+
if (logBucketProp !== undefined) {
|
|
2466
|
+
// Use external bucket
|
|
2467
|
+
logBucket = this.resolveLogBucket(logBucketProp);
|
|
2468
|
+
}
|
|
2469
|
+
else if (destinationProp !== false) {
|
|
2470
|
+
// Create new bucket (original behavior)
|
|
2471
|
+
const createdBucket = new s3__namespace.Bucket(this, constructEnvName("LogBucket"), {
|
|
2468
2472
|
autoDeleteObjects: true,
|
|
2469
2473
|
lifecycleRules: [
|
|
2470
2474
|
{
|
|
@@ -2477,15 +2481,21 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
2477
2481
|
],
|
|
2478
2482
|
},
|
|
2479
2483
|
],
|
|
2484
|
+
objectOwnership: s3__namespace.ObjectOwnership.OBJECT_WRITER,
|
|
2485
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
2480
2486
|
});
|
|
2481
|
-
cdk.Tags.of(
|
|
2482
|
-
|
|
2487
|
+
cdk.Tags.of(createdBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
|
|
2488
|
+
logBucket = createdBucket;
|
|
2489
|
+
}
|
|
2490
|
+
// Add S3 notifications if we have a bucket and destination is not false
|
|
2491
|
+
if (logBucket && destinationProp !== false && !isExternalBucket) {
|
|
2492
|
+
// Only add notifications to buckets we created (not external buckets)
|
|
2483
2493
|
const lambdaDestination = destinationProp === true
|
|
2484
2494
|
? new s3n.LambdaDestination(resolveDatadogForwarderFunction(this))
|
|
2485
2495
|
: destinationProp;
|
|
2486
2496
|
logBucket.addEventNotification(s3__namespace.EventType.OBJECT_CREATED, lambdaDestination);
|
|
2487
|
-
this.logBucket = logBucket;
|
|
2488
2497
|
}
|
|
2498
|
+
this.logBucket = logBucket;
|
|
2489
2499
|
// Create the CloudFront distribution
|
|
2490
2500
|
this.distribution = new cloudfront__namespace.Distribution(this, constructEnvName("Distribution"), {
|
|
2491
2501
|
defaultBehavior,
|
|
@@ -2556,6 +2566,30 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
2556
2566
|
"invokeMode" in handler &&
|
|
2557
2567
|
typeof handler.invokeMode === "string");
|
|
2558
2568
|
}
|
|
2569
|
+
isExportNameObject(value) {
|
|
2570
|
+
return (typeof value === "object" &&
|
|
2571
|
+
value !== null &&
|
|
2572
|
+
"exportName" in value &&
|
|
2573
|
+
typeof value.exportName === "string");
|
|
2574
|
+
}
|
|
2575
|
+
resolveLogBucket(logBucketProp) {
|
|
2576
|
+
// true = use account logging bucket
|
|
2577
|
+
if (logBucketProp === true) {
|
|
2578
|
+
const bucketName = cdk.Fn.importValue(CDK$2.IMPORT.LOG_BUCKET);
|
|
2579
|
+
return s3__namespace.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
|
|
2580
|
+
}
|
|
2581
|
+
// { exportName: string } = import from CloudFormation export
|
|
2582
|
+
if (this.isExportNameObject(logBucketProp)) {
|
|
2583
|
+
const bucketName = cdk.Fn.importValue(logBucketProp.exportName);
|
|
2584
|
+
return s3__namespace.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
|
|
2585
|
+
}
|
|
2586
|
+
// string = bucket name
|
|
2587
|
+
if (typeof logBucketProp === "string") {
|
|
2588
|
+
return s3__namespace.Bucket.fromBucketName(this, "ImportedLogBucket", logBucketProp);
|
|
2589
|
+
}
|
|
2590
|
+
// IBucket = use directly
|
|
2591
|
+
return logBucketProp;
|
|
2592
|
+
}
|
|
2559
2593
|
// Implement IDistribution interface
|
|
2560
2594
|
get env() {
|
|
2561
2595
|
return {
|