@jaypie/constructs 1.1.62-rc.1 → 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/cjs/index.cjs
CHANGED
|
@@ -1666,7 +1666,7 @@ class JaypieDatadogForwarder extends constructs.Construct {
|
|
|
1666
1666
|
class JaypieDistribution extends constructs.Construct {
|
|
1667
1667
|
constructor(scope, id, props) {
|
|
1668
1668
|
super(scope, id);
|
|
1669
|
-
const { certificate: certificateProp = true, handler, host: propsHost, invokeMode = lambda__namespace.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.API, zone: propsZone,
|
|
1669
|
+
const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda__namespace.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
|
|
1670
1670
|
// Validate environment variables
|
|
1671
1671
|
if (process.env.CDK_ENV_API_SUBDOMAIN &&
|
|
1672
1672
|
!isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
|
|
@@ -1732,9 +1732,10 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
1732
1732
|
}
|
|
1733
1733
|
else if (origin) {
|
|
1734
1734
|
defaultBehavior = {
|
|
1735
|
+
allowedMethods: cloudfront__namespace.AllowedMethods.ALLOW_ALL,
|
|
1735
1736
|
cachePolicy: cloudfront__namespace.CachePolicy.CACHING_DISABLED,
|
|
1736
1737
|
origin,
|
|
1737
|
-
originRequestPolicy: cloudfront__namespace.OriginRequestPolicy.
|
|
1738
|
+
originRequestPolicy: cloudfront__namespace.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
1738
1739
|
viewerProtocolPolicy: cloudfront__namespace.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
1739
1740
|
};
|
|
1740
1741
|
}
|
|
@@ -1759,6 +1760,33 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
1759
1760
|
}
|
|
1760
1761
|
this.certificate = certificateToUse;
|
|
1761
1762
|
}
|
|
1763
|
+
// Create log bucket if logging is enabled
|
|
1764
|
+
let logBucket;
|
|
1765
|
+
if (destinationProp !== false) {
|
|
1766
|
+
logBucket = new s3__namespace.Bucket(this, constructEnvName("LogBucket"), {
|
|
1767
|
+
objectOwnership: s3__namespace.ObjectOwnership.OBJECT_WRITER,
|
|
1768
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
1769
|
+
autoDeleteObjects: true,
|
|
1770
|
+
lifecycleRules: [
|
|
1771
|
+
{
|
|
1772
|
+
expiration: cdk.Duration.days(90),
|
|
1773
|
+
transitions: [
|
|
1774
|
+
{
|
|
1775
|
+
storageClass: s3__namespace.StorageClass.INFREQUENT_ACCESS,
|
|
1776
|
+
transitionAfter: cdk.Duration.days(30),
|
|
1777
|
+
},
|
|
1778
|
+
],
|
|
1779
|
+
},
|
|
1780
|
+
],
|
|
1781
|
+
});
|
|
1782
|
+
cdk.Tags.of(logBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
|
|
1783
|
+
// Add S3 notification to Datadog forwarder
|
|
1784
|
+
const lambdaDestination = destinationProp === true
|
|
1785
|
+
? new s3n.LambdaDestination(resolveDatadogForwarderFunction(this))
|
|
1786
|
+
: destinationProp;
|
|
1787
|
+
logBucket.addEventNotification(s3__namespace.EventType.OBJECT_CREATED, lambdaDestination);
|
|
1788
|
+
this.logBucket = logBucket;
|
|
1789
|
+
}
|
|
1762
1790
|
// Create the CloudFront distribution
|
|
1763
1791
|
this.distribution = new cloudfront__namespace.Distribution(this, constructEnvName("Distribution"), {
|
|
1764
1792
|
defaultBehavior,
|
|
@@ -1768,6 +1796,13 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
1768
1796
|
domainNames: [host],
|
|
1769
1797
|
}
|
|
1770
1798
|
: {}),
|
|
1799
|
+
...(logBucket
|
|
1800
|
+
? {
|
|
1801
|
+
enableLogging: true,
|
|
1802
|
+
logBucket,
|
|
1803
|
+
logFilePrefix: "cloudfront-logs/",
|
|
1804
|
+
}
|
|
1805
|
+
: {}),
|
|
1771
1806
|
...distributionProps,
|
|
1772
1807
|
});
|
|
1773
1808
|
cdk.Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
|
|
@@ -1775,14 +1810,20 @@ class JaypieDistribution extends constructs.Construct {
|
|
|
1775
1810
|
this.distributionDomainName = this.distribution.distributionDomainName;
|
|
1776
1811
|
this.distributionId = this.distribution.distributionId;
|
|
1777
1812
|
this.domainName = this.distribution.domainName;
|
|
1778
|
-
// Create DNS
|
|
1813
|
+
// Create DNS records if we have host and zone
|
|
1779
1814
|
if (host && hostedZone) {
|
|
1780
|
-
const
|
|
1815
|
+
const aRecord = new route53__namespace.ARecord(this, "AliasRecord", {
|
|
1781
1816
|
recordName: host,
|
|
1782
1817
|
target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.CloudFrontTarget(this.distribution)),
|
|
1783
1818
|
zone: hostedZone,
|
|
1784
1819
|
});
|
|
1785
|
-
cdk.Tags.of(
|
|
1820
|
+
cdk.Tags.of(aRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
|
|
1821
|
+
const aaaaRecord = new route53__namespace.AaaaRecord(this, "AaaaAliasRecord", {
|
|
1822
|
+
recordName: host,
|
|
1823
|
+
target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.CloudFrontTarget(this.distribution)),
|
|
1824
|
+
zone: hostedZone,
|
|
1825
|
+
});
|
|
1826
|
+
cdk.Tags.of(aaaaRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
|
|
1786
1827
|
}
|
|
1787
1828
|
}
|
|
1788
1829
|
// Type guards for handler types
|