@jaypie/constructs 1.1.62-rc.2 → 1.1.62-rc.3
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.
|
@@ -3,6 +3,8 @@ import * as acm from "aws-cdk-lib/aws-certificatemanager";
|
|
|
3
3
|
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
|
|
4
4
|
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
5
5
|
import * as route53 from "aws-cdk-lib/aws-route53";
|
|
6
|
+
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
7
|
+
import { LambdaDestination } from "aws-cdk-lib/aws-s3-notifications";
|
|
6
8
|
import { Construct } from "constructs";
|
|
7
9
|
export interface JaypieDistributionProps extends Omit<cloudfront.DistributionProps, "certificate" | "defaultBehavior"> {
|
|
8
10
|
/**
|
|
@@ -14,6 +16,14 @@ export interface JaypieDistributionProps extends Omit<cloudfront.DistributionPro
|
|
|
14
16
|
* Override default behavior (optional if handler is provided)
|
|
15
17
|
*/
|
|
16
18
|
defaultBehavior?: cloudfront.BehaviorOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Log destination configuration for CloudFront access logs
|
|
21
|
+
* - LambdaDestination: Use a specific Lambda destination for S3 notifications
|
|
22
|
+
* - true: Use Datadog forwarder for S3 notifications (default)
|
|
23
|
+
* - false: Disable logging entirely
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
destination?: LambdaDestination | boolean;
|
|
17
27
|
/**
|
|
18
28
|
* The origin handler - can be an IOrigin, IFunctionUrl, or IFunction
|
|
19
29
|
* If IFunction, a FunctionUrl will be created with auth NONE
|
|
@@ -49,6 +59,7 @@ export declare class JaypieDistribution extends Construct implements cloudfront.
|
|
|
49
59
|
readonly domainName: string;
|
|
50
60
|
readonly functionUrl?: lambda.FunctionUrl;
|
|
51
61
|
readonly host?: string;
|
|
62
|
+
readonly logBucket?: s3.IBucket;
|
|
52
63
|
constructor(scope: Construct, id: string, props: JaypieDistributionProps);
|
|
53
64
|
private isIOrigin;
|
|
54
65
|
private isIFunctionUrl;
|
package/dist/esm/index.js
CHANGED
|
@@ -1635,7 +1635,7 @@ class JaypieDatadogForwarder extends Construct {
|
|
|
1635
1635
|
class JaypieDistribution extends Construct {
|
|
1636
1636
|
constructor(scope, id, props) {
|
|
1637
1637
|
super(scope, id);
|
|
1638
|
-
const { certificate: certificateProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.API, zone: propsZone,
|
|
1638
|
+
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
1639
1639
|
// Validate environment variables
|
|
1640
1640
|
if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
1641
1641
|
!isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
|
|
@@ -1701,9 +1701,10 @@ class JaypieDistribution extends Construct {
|
|
|
1701
1701
|
}
|
|
1702
1702
|
else if (origin) {
|
|
1703
1703
|
defaultBehavior = {
|
|
1704
|
+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
|
|
1704
1705
|
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
|
|
1705
1706
|
origin,
|
|
1706
|
-
originRequestPolicy: cloudfront.OriginRequestPolicy.
|
|
1707
|
+
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
1707
1708
|
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
1708
1709
|
};
|
|
1709
1710
|
}
|
|
@@ -1728,6 +1729,33 @@ class JaypieDistribution extends Construct {
|
|
|
1728
1729
|
}
|
|
1729
1730
|
this.certificate = certificateToUse;
|
|
1730
1731
|
}
|
|
1732
|
+
// Create log bucket if logging is enabled
|
|
1733
|
+
let logBucket;
|
|
1734
|
+
if (destinationProp !== false) {
|
|
1735
|
+
logBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
|
|
1736
|
+
objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
|
|
1737
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
1738
|
+
autoDeleteObjects: true,
|
|
1739
|
+
lifecycleRules: [
|
|
1740
|
+
{
|
|
1741
|
+
expiration: Duration.days(90),
|
|
1742
|
+
transitions: [
|
|
1743
|
+
{
|
|
1744
|
+
storageClass: s3.StorageClass.INFREQUENT_ACCESS,
|
|
1745
|
+
transitionAfter: Duration.days(30),
|
|
1746
|
+
},
|
|
1747
|
+
],
|
|
1748
|
+
},
|
|
1749
|
+
],
|
|
1750
|
+
});
|
|
1751
|
+
Tags.of(logBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
|
|
1752
|
+
// Add S3 notification to Datadog forwarder
|
|
1753
|
+
const lambdaDestination = destinationProp === true
|
|
1754
|
+
? new LambdaDestination(resolveDatadogForwarderFunction(this))
|
|
1755
|
+
: destinationProp;
|
|
1756
|
+
logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, lambdaDestination);
|
|
1757
|
+
this.logBucket = logBucket;
|
|
1758
|
+
}
|
|
1731
1759
|
// Create the CloudFront distribution
|
|
1732
1760
|
this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
|
|
1733
1761
|
defaultBehavior,
|
|
@@ -1737,6 +1765,13 @@ class JaypieDistribution extends Construct {
|
|
|
1737
1765
|
domainNames: [host],
|
|
1738
1766
|
}
|
|
1739
1767
|
: {}),
|
|
1768
|
+
...(logBucket
|
|
1769
|
+
? {
|
|
1770
|
+
enableLogging: true,
|
|
1771
|
+
logBucket,
|
|
1772
|
+
logFilePrefix: "cloudfront-logs/",
|
|
1773
|
+
}
|
|
1774
|
+
: {}),
|
|
1740
1775
|
...distributionProps,
|
|
1741
1776
|
});
|
|
1742
1777
|
Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
|