@gradientedge/cdk-utils 8.109.0 → 8.110.0
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/src/lib/construct/site-with-ecs-backend/main.d.ts +2 -0
- package/dist/src/lib/construct/site-with-ecs-backend/main.js +20 -0
- package/dist/src/lib/construct/site-with-ecs-backend/types.d.ts +7 -1
- package/package.json +1 -1
- package/src/lib/construct/site-with-ecs-backend/main.ts +21 -0
- package/src/lib/construct/site-with-ecs-backend/types.ts +8 -0
|
@@ -61,6 +61,7 @@ export declare class SiteWithEcsBackend extends CommonConstruct {
|
|
|
61
61
|
siteFunctionAssociations: cloudfront.FunctionAssociation[];
|
|
62
62
|
siteOriginRequestPolicy: cloudfront.OriginRequestPolicy;
|
|
63
63
|
siteOriginResponseHeadersPolicy?: cloudfront.ResponseHeadersPolicy;
|
|
64
|
+
siteCachePolicy: cloudfront.CachePolicy;
|
|
64
65
|
constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps);
|
|
65
66
|
/**
|
|
66
67
|
* @summary Initialise and provision resources
|
|
@@ -125,6 +126,7 @@ export declare class SiteWithEcsBackend extends CommonConstruct {
|
|
|
125
126
|
* Method to create log bucket for site distribution
|
|
126
127
|
*/
|
|
127
128
|
protected createSiteLogBucket(): void;
|
|
129
|
+
protected createSiteCacheConfigPolicy(): void;
|
|
128
130
|
protected createSiteOriginRequestPolicy(): void;
|
|
129
131
|
protected createResponseHeaderPolicy(props: SiteResponseHeadersPolicyProps): cdk.aws_cloudfront.ResponseHeadersPolicy | undefined;
|
|
130
132
|
protected createSiteOriginResponseHeadersPolicy(): void;
|
|
@@ -80,6 +80,7 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
80
80
|
siteFunctionAssociations;
|
|
81
81
|
siteOriginRequestPolicy;
|
|
82
82
|
siteOriginResponseHeadersPolicy;
|
|
83
|
+
siteCachePolicy;
|
|
83
84
|
constructor(parent, id, props) {
|
|
84
85
|
super(parent, id, props);
|
|
85
86
|
this.props = props;
|
|
@@ -103,6 +104,7 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
103
104
|
this.createEcsBuildArgs();
|
|
104
105
|
this.createEcsContainerImage();
|
|
105
106
|
this.createEcsService();
|
|
107
|
+
this.createSiteCacheConfigPolicy();
|
|
106
108
|
this.createSiteOriginRequestPolicy();
|
|
107
109
|
this.createSiteOriginResponseHeadersPolicy();
|
|
108
110
|
this.createSiteOrigin();
|
|
@@ -345,6 +347,24 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
345
347
|
createSiteLogBucket() {
|
|
346
348
|
this.siteLogBucket = this.s3Manager.createS3Bucket(`${this.id}-site-logs`, this, this.props.siteLogBucket);
|
|
347
349
|
}
|
|
350
|
+
createSiteCacheConfigPolicy() {
|
|
351
|
+
if (!this.props.siteCachePolicy)
|
|
352
|
+
return;
|
|
353
|
+
this.siteCachePolicy = new cloudfront.CachePolicy(this, `${this.id}-site-cache-policy`, {
|
|
354
|
+
cachePolicyName: `${this.id}-site-cache-policy`,
|
|
355
|
+
comment: `Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
356
|
+
defaultTtl: cdk.Duration.seconds(this.props.siteCachePolicy.defaultTtlInSeconds),
|
|
357
|
+
minTtl: cdk.Duration.seconds(this.props.siteCachePolicy.minTtlInSeconds),
|
|
358
|
+
maxTtl: cdk.Duration.seconds(this.props.siteCachePolicy.maxTtlInSeconds),
|
|
359
|
+
enableAcceptEncodingGzip: this.props.siteCachePolicy.enableAcceptEncodingGzip,
|
|
360
|
+
queryStringBehavior: this.props.siteCachePolicy.queryStringBehavior,
|
|
361
|
+
headerBehavior: this.props.siteCachePolicy.headerBehavior,
|
|
362
|
+
cookieBehavior: this.props.siteCachePolicy.cookieBehavior,
|
|
363
|
+
});
|
|
364
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
365
|
+
cachePolicy: this.siteCachePolicy,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
348
368
|
createSiteOriginRequestPolicy() {
|
|
349
369
|
if (!this.props.siteOriginRequestPolicy)
|
|
350
370
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommonStackProps } from '../../common';
|
|
2
2
|
import { AcmProps, CloudfrontFunctionProps, DistributionProps, EcsApplicationLoadBalancedFargateServiceProps, EcsClusterProps, EfsAccessPointOptions, EfsFileSystemProps, HealthCheck, LogProps, S3BucketProps } from '../../services';
|
|
3
3
|
import { VpcProps } from 'aws-cdk-lib/aws-ec2';
|
|
4
|
-
import { OriginRequestPolicyProps, ResponseHeadersStrictTransportSecurity, ResponseSecurityHeadersBehavior, ResponseHeadersPolicyProps } from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import { OriginRequestPolicyProps, ResponseHeadersStrictTransportSecurity, ResponseSecurityHeadersBehavior, ResponseHeadersPolicyProps, CachePolicyProps } from 'aws-cdk-lib/aws-cloudfront';
|
|
5
5
|
import { SiteResponseHeaderPolicyType } from './constants';
|
|
6
6
|
/**
|
|
7
7
|
*/
|
|
@@ -20,6 +20,7 @@ export interface SiteWithEcsBackendProps extends CommonStackProps {
|
|
|
20
20
|
siteHealthCheck: HealthCheck;
|
|
21
21
|
siteLog: LogProps;
|
|
22
22
|
siteLogBucket: S3BucketProps;
|
|
23
|
+
siteCachePolicy?: SiteCachePolicyProps;
|
|
23
24
|
siteOriginRequestPolicy: OriginRequestPolicyProps;
|
|
24
25
|
siteOriginResponseHeadersPolicy: SiteResponseHeadersPolicyProps;
|
|
25
26
|
siteRecordName?: string;
|
|
@@ -41,3 +42,8 @@ export interface SiteResponseHeadersPolicyProps extends ResponseHeadersPolicyPro
|
|
|
41
42
|
securityHeadersBehavior: SiteSecurityHeadersBehavior;
|
|
42
43
|
type: SiteResponseHeaderPolicyType;
|
|
43
44
|
}
|
|
45
|
+
export interface SiteCachePolicyProps extends CachePolicyProps {
|
|
46
|
+
defaultTtlInSeconds: number;
|
|
47
|
+
minTtlInSeconds: number;
|
|
48
|
+
maxTtlInSeconds: number;
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -65,6 +65,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
65
65
|
siteFunctionAssociations: cloudfront.FunctionAssociation[]
|
|
66
66
|
siteOriginRequestPolicy: cloudfront.OriginRequestPolicy
|
|
67
67
|
siteOriginResponseHeadersPolicy?: cloudfront.ResponseHeadersPolicy
|
|
68
|
+
siteCachePolicy: cloudfront.CachePolicy
|
|
68
69
|
|
|
69
70
|
constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps) {
|
|
70
71
|
super(parent, id, props)
|
|
@@ -91,6 +92,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
91
92
|
this.createEcsBuildArgs()
|
|
92
93
|
this.createEcsContainerImage()
|
|
93
94
|
this.createEcsService()
|
|
95
|
+
this.createSiteCacheConfigPolicy()
|
|
94
96
|
this.createSiteOriginRequestPolicy()
|
|
95
97
|
this.createSiteOriginResponseHeadersPolicy()
|
|
96
98
|
this.createSiteOrigin()
|
|
@@ -408,6 +410,25 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
408
410
|
this.siteLogBucket = this.s3Manager.createS3Bucket(`${this.id}-site-logs`, this, this.props.siteLogBucket)
|
|
409
411
|
}
|
|
410
412
|
|
|
413
|
+
protected createSiteCacheConfigPolicy() {
|
|
414
|
+
if (!this.props.siteCachePolicy) return
|
|
415
|
+
this.siteCachePolicy = new cloudfront.CachePolicy(this, `${this.id}-site-cache-policy`, {
|
|
416
|
+
cachePolicyName: `${this.id}-site-cache-policy`,
|
|
417
|
+
comment: `Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
418
|
+
defaultTtl: cdk.Duration.seconds(this.props.siteCachePolicy.defaultTtlInSeconds),
|
|
419
|
+
minTtl: cdk.Duration.seconds(this.props.siteCachePolicy.minTtlInSeconds),
|
|
420
|
+
maxTtl: cdk.Duration.seconds(this.props.siteCachePolicy.maxTtlInSeconds),
|
|
421
|
+
enableAcceptEncodingGzip: this.props.siteCachePolicy.enableAcceptEncodingGzip,
|
|
422
|
+
queryStringBehavior: this.props.siteCachePolicy.queryStringBehavior,
|
|
423
|
+
headerBehavior: this.props.siteCachePolicy.headerBehavior,
|
|
424
|
+
cookieBehavior: this.props.siteCachePolicy.cookieBehavior,
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
428
|
+
cachePolicy: this.siteCachePolicy,
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
|
|
411
432
|
protected createSiteOriginRequestPolicy() {
|
|
412
433
|
if (!this.props.siteOriginRequestPolicy) return
|
|
413
434
|
this.siteOriginRequestPolicy = new cloudfront.OriginRequestPolicy(this, `${this.id}-sorp`, {
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
ResponseHeadersStrictTransportSecurity,
|
|
18
18
|
ResponseSecurityHeadersBehavior,
|
|
19
19
|
ResponseHeadersPolicyProps,
|
|
20
|
+
CachePolicyProps,
|
|
20
21
|
} from 'aws-cdk-lib/aws-cloudfront'
|
|
21
22
|
import { SiteResponseHeaderPolicyType } from './constants'
|
|
22
23
|
|
|
@@ -37,6 +38,7 @@ export interface SiteWithEcsBackendProps extends CommonStackProps {
|
|
|
37
38
|
siteHealthCheck: HealthCheck
|
|
38
39
|
siteLog: LogProps
|
|
39
40
|
siteLogBucket: S3BucketProps
|
|
41
|
+
siteCachePolicy?: SiteCachePolicyProps
|
|
40
42
|
siteOriginRequestPolicy: OriginRequestPolicyProps
|
|
41
43
|
siteOriginResponseHeadersPolicy: SiteResponseHeadersPolicyProps
|
|
42
44
|
siteRecordName?: string
|
|
@@ -61,3 +63,9 @@ export interface SiteResponseHeadersPolicyProps extends ResponseHeadersPolicyPro
|
|
|
61
63
|
securityHeadersBehavior: SiteSecurityHeadersBehavior
|
|
62
64
|
type: SiteResponseHeaderPolicyType
|
|
63
65
|
}
|
|
66
|
+
|
|
67
|
+
export interface SiteCachePolicyProps extends CachePolicyProps {
|
|
68
|
+
defaultTtlInSeconds: number
|
|
69
|
+
minTtlInSeconds: number
|
|
70
|
+
maxTtlInSeconds: number
|
|
71
|
+
}
|