@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/esm/index.js
CHANGED
|
@@ -2325,7 +2325,7 @@ class JaypieDatadogSecret extends JaypieEnvSecret {
|
|
|
2325
2325
|
class JaypieDistribution extends Construct {
|
|
2326
2326
|
constructor(scope, id, props) {
|
|
2327
2327
|
super(scope, id);
|
|
2328
|
-
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, originReadTimeout = Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
2328
|
+
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, logBucket: logBucketProp, originReadTimeout = Duration.seconds(CDK$2.DURATION.CLOUDFRONT_API), roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
2329
2329
|
// Validate environment variables
|
|
2330
2330
|
if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
2331
2331
|
!isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
|
|
@@ -2427,12 +2427,16 @@ class JaypieDistribution extends Construct {
|
|
|
2427
2427
|
});
|
|
2428
2428
|
this.certificate = certificateToUse;
|
|
2429
2429
|
}
|
|
2430
|
-
//
|
|
2430
|
+
// Resolve or create log bucket
|
|
2431
2431
|
let logBucket;
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2432
|
+
const isExternalBucket = logBucketProp !== undefined;
|
|
2433
|
+
if (logBucketProp !== undefined) {
|
|
2434
|
+
// Use external bucket
|
|
2435
|
+
logBucket = this.resolveLogBucket(logBucketProp);
|
|
2436
|
+
}
|
|
2437
|
+
else if (destinationProp !== false) {
|
|
2438
|
+
// Create new bucket (original behavior)
|
|
2439
|
+
const createdBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
|
|
2436
2440
|
autoDeleteObjects: true,
|
|
2437
2441
|
lifecycleRules: [
|
|
2438
2442
|
{
|
|
@@ -2445,15 +2449,21 @@ class JaypieDistribution extends Construct {
|
|
|
2445
2449
|
],
|
|
2446
2450
|
},
|
|
2447
2451
|
],
|
|
2452
|
+
objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
|
|
2453
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
2448
2454
|
});
|
|
2449
|
-
Tags.of(
|
|
2450
|
-
|
|
2455
|
+
Tags.of(createdBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
|
|
2456
|
+
logBucket = createdBucket;
|
|
2457
|
+
}
|
|
2458
|
+
// Add S3 notifications if we have a bucket and destination is not false
|
|
2459
|
+
if (logBucket && destinationProp !== false && !isExternalBucket) {
|
|
2460
|
+
// Only add notifications to buckets we created (not external buckets)
|
|
2451
2461
|
const lambdaDestination = destinationProp === true
|
|
2452
2462
|
? new LambdaDestination(resolveDatadogForwarderFunction(this))
|
|
2453
2463
|
: destinationProp;
|
|
2454
2464
|
logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, lambdaDestination);
|
|
2455
|
-
this.logBucket = logBucket;
|
|
2456
2465
|
}
|
|
2466
|
+
this.logBucket = logBucket;
|
|
2457
2467
|
// Create the CloudFront distribution
|
|
2458
2468
|
this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
|
|
2459
2469
|
defaultBehavior,
|
|
@@ -2524,6 +2534,30 @@ class JaypieDistribution extends Construct {
|
|
|
2524
2534
|
"invokeMode" in handler &&
|
|
2525
2535
|
typeof handler.invokeMode === "string");
|
|
2526
2536
|
}
|
|
2537
|
+
isExportNameObject(value) {
|
|
2538
|
+
return (typeof value === "object" &&
|
|
2539
|
+
value !== null &&
|
|
2540
|
+
"exportName" in value &&
|
|
2541
|
+
typeof value.exportName === "string");
|
|
2542
|
+
}
|
|
2543
|
+
resolveLogBucket(logBucketProp) {
|
|
2544
|
+
// true = use account logging bucket
|
|
2545
|
+
if (logBucketProp === true) {
|
|
2546
|
+
const bucketName = Fn.importValue(CDK$2.IMPORT.LOG_BUCKET);
|
|
2547
|
+
return s3.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
|
|
2548
|
+
}
|
|
2549
|
+
// { exportName: string } = import from CloudFormation export
|
|
2550
|
+
if (this.isExportNameObject(logBucketProp)) {
|
|
2551
|
+
const bucketName = Fn.importValue(logBucketProp.exportName);
|
|
2552
|
+
return s3.Bucket.fromBucketName(this, "ImportedLogBucket", bucketName);
|
|
2553
|
+
}
|
|
2554
|
+
// string = bucket name
|
|
2555
|
+
if (typeof logBucketProp === "string") {
|
|
2556
|
+
return s3.Bucket.fromBucketName(this, "ImportedLogBucket", logBucketProp);
|
|
2557
|
+
}
|
|
2558
|
+
// IBucket = use directly
|
|
2559
|
+
return logBucketProp;
|
|
2560
|
+
}
|
|
2527
2561
|
// Implement IDistribution interface
|
|
2528
2562
|
get env() {
|
|
2529
2563
|
return {
|