@gradientedge/cdk-utils 6.0.1 → 6.3.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/static-site/main.d.ts +5 -0
- package/dist/src/lib/construct/static-site/main.js +10 -0
- package/dist/src/lib/manager/aws/cloudfront-manager.d.ts +2 -1
- package/dist/src/lib/manager/aws/cloudfront-manager.js +3 -1
- package/dist/src/lib/manager/aws/lambda-manager.js +1 -0
- package/dist/src/lib/types/aws/index.d.ts +1 -0
- package/package.json +13 -13
- package/src/lib/construct/static-site/main.ts +16 -0
- package/src/lib/manager/aws/cloudfront-manager.ts +4 -1
- package/src/lib/manager/aws/lambda-manager.ts +1 -0
- package/src/lib/types/aws/index.ts +1 -0
|
@@ -81,6 +81,11 @@ export declare class StaticSite extends CommonConstruct {
|
|
|
81
81
|
* @protected
|
|
82
82
|
*/
|
|
83
83
|
protected createSiteDistribution(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
86
|
+
* @protected
|
|
87
|
+
*/
|
|
88
|
+
protected invalidateDistributionCache(): void;
|
|
84
89
|
/**
|
|
85
90
|
* @summary Method to create route53 records for static site
|
|
86
91
|
* @protected
|
|
@@ -80,6 +80,7 @@ class StaticSite extends common_1.CommonConstruct {
|
|
|
80
80
|
this.createSiteCloudfrontFunction();
|
|
81
81
|
this.resolveSiteFunctionAssociations();
|
|
82
82
|
this.createSiteDistribution();
|
|
83
|
+
this.invalidateDistributionCache();
|
|
83
84
|
this.createSiteRouteAssets();
|
|
84
85
|
this.deploySite();
|
|
85
86
|
}
|
|
@@ -151,6 +152,15 @@ class StaticSite extends common_1.CommonConstruct {
|
|
|
151
152
|
throw 'SiteDistribution props undefined';
|
|
152
153
|
this.siteDistribution = this.cloudFrontManager.createDistributionWithS3Origin(`${this.id}-distribution`, this, this.props.siteDistribution, this.siteOrigin, this.siteBucket, this.siteLogBucket, this.siteOriginAccessIdentity, this.siteCertificate, this.props.siteAliases, this.siteFunctionAssociations);
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
157
|
+
* @protected
|
|
158
|
+
*/
|
|
159
|
+
invalidateDistributionCache() {
|
|
160
|
+
if (this.props.siteCacheInvalidationDockerFilePath) {
|
|
161
|
+
this.cloudFrontManager.invalidateCache(`${this.id}-cache-invalidation`, this, this.props.siteCacheInvalidationDockerFilePath, this.siteDistribution.distributionId);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
154
164
|
/**
|
|
155
165
|
* @summary Method to create route53 records for static site
|
|
156
166
|
* @protected
|
|
@@ -75,8 +75,9 @@ export declare class CloudFrontManager {
|
|
|
75
75
|
* @param {s3.IBucket?} logBucket
|
|
76
76
|
* @param {acm.ICertificate?} certificate
|
|
77
77
|
* @param {cloudfront.FunctionAssociation?} defaultFunctionAssociations
|
|
78
|
+
* @param {cloudfront.IResponseHeadersPolicy?} responseHeadersPolicy
|
|
78
79
|
*/
|
|
79
|
-
createDistributionWithHttpOrigin(id: string, scope: common.CommonConstruct, props: types.DistributionProps, origin: origins.HttpOrigin, domainNames: string[], logBucket?: s3.IBucket, certificate?: acm.ICertificate, defaultFunctionAssociations?: cloudfront.FunctionAssociation[]): cdk.aws_cloudfront.Distribution;
|
|
80
|
+
createDistributionWithHttpOrigin(id: string, scope: common.CommonConstruct, props: types.DistributionProps, origin: origins.HttpOrigin, domainNames: string[], logBucket?: s3.IBucket, certificate?: acm.ICertificate, defaultFunctionAssociations?: cloudfront.FunctionAssociation[], responseHeadersPolicy?: cloudfront.IResponseHeadersPolicy): cdk.aws_cloudfront.Distribution;
|
|
80
81
|
/**
|
|
81
82
|
* @summary Method to provision a Lambda@Edge function
|
|
82
83
|
*
|
|
@@ -173,8 +173,9 @@ class CloudFrontManager {
|
|
|
173
173
|
* @param {s3.IBucket?} logBucket
|
|
174
174
|
* @param {acm.ICertificate?} certificate
|
|
175
175
|
* @param {cloudfront.FunctionAssociation?} defaultFunctionAssociations
|
|
176
|
+
* @param {cloudfront.IResponseHeadersPolicy?} responseHeadersPolicy
|
|
176
177
|
*/
|
|
177
|
-
createDistributionWithHttpOrigin(id, scope, props, origin, domainNames, logBucket, certificate, defaultFunctionAssociations) {
|
|
178
|
+
createDistributionWithHttpOrigin(id, scope, props, origin, domainNames, logBucket, certificate, defaultFunctionAssociations, responseHeadersPolicy) {
|
|
178
179
|
const distribution = new cloudfront.Distribution(scope, `${id}`, {
|
|
179
180
|
certificate: certificate,
|
|
180
181
|
comment: `${id} - ${scope.props.stage} stage`,
|
|
@@ -184,6 +185,7 @@ class CloudFrontManager {
|
|
|
184
185
|
originRequestPolicy: props.defaultBehavior ? props.defaultBehavior.originRequestPolicy : undefined,
|
|
185
186
|
functionAssociations: defaultFunctionAssociations ?? undefined,
|
|
186
187
|
viewerProtocolPolicy: props.defaultBehavior ? props.defaultBehavior.viewerProtocolPolicy : undefined,
|
|
188
|
+
responseHeadersPolicy: responseHeadersPolicy ?? undefined,
|
|
187
189
|
},
|
|
188
190
|
additionalBehaviors: props.additionalBehaviors,
|
|
189
191
|
defaultRootObject: props.defaultRootObject,
|
|
@@ -115,6 +115,7 @@ class LambdaManager {
|
|
|
115
115
|
timeout: props.timeoutInSecs ? cdk.Duration.seconds(props.timeoutInSecs) : cdk.Duration.minutes(1),
|
|
116
116
|
vpc: vpc,
|
|
117
117
|
vpcSubnets: vpcSubnets,
|
|
118
|
+
tracing: props.tracing,
|
|
118
119
|
},
|
|
119
120
|
});
|
|
120
121
|
utils.createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn);
|
|
@@ -82,6 +82,7 @@ export interface SiteWithEcsBackendProps extends CommonStackProps {
|
|
|
82
82
|
* @subcategory Properties
|
|
83
83
|
*/
|
|
84
84
|
export interface StaticSiteProps extends CommonStackProps {
|
|
85
|
+
siteCacheInvalidationDockerFilePath?: string;
|
|
85
86
|
siteCreateAltARecord: boolean;
|
|
86
87
|
siteCertificate: AcmProps;
|
|
87
88
|
siteBucket: S3BucketProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@types/lodash": "^4.14.182",
|
|
49
|
-
"@types/node": "^18.6
|
|
50
|
-
"app-root-path": "^3.
|
|
51
|
-
"aws-cdk-lib": "^2.
|
|
52
|
-
"aws-sdk": "^2.
|
|
53
|
-
"constructs": "^10.1.
|
|
49
|
+
"@types/node": "^18.7.6",
|
|
50
|
+
"app-root-path": "^3.1.0",
|
|
51
|
+
"aws-cdk-lib": "^2.37.1",
|
|
52
|
+
"aws-sdk": "^2.1195.0",
|
|
53
|
+
"constructs": "^10.1.77",
|
|
54
54
|
"lodash": "^4.17.21",
|
|
55
55
|
"moment": "^2.29.4",
|
|
56
56
|
"nconf": "^0.12.0",
|
|
@@ -59,16 +59,16 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
62
|
-
"@types/jest": "^28.1.
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
64
|
-
"@typescript-eslint/parser": "^5.
|
|
62
|
+
"@types/jest": "^28.1.7",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
64
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
65
65
|
"aws-cdk": "*",
|
|
66
66
|
"babel-eslint": "^10.1.0",
|
|
67
67
|
"better-docs": "^2.7.2",
|
|
68
68
|
"codecov": "^3.8.3",
|
|
69
69
|
"commitizen": "^4.2.5",
|
|
70
70
|
"dotenv": "^16.0.1",
|
|
71
|
-
"eslint": "^8.
|
|
71
|
+
"eslint": "^8.22.0",
|
|
72
72
|
"eslint-config-prettier": "^8.5.0",
|
|
73
73
|
"eslint-plugin-import": "^2.26.0",
|
|
74
74
|
"husky": "^8.0.1",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"jsdoc": "^3.6.11",
|
|
79
79
|
"jsdoc-babel": "^0.5.0",
|
|
80
80
|
"jsdoc-mermaid": "^1.0.0",
|
|
81
|
-
"lerna": "^5.
|
|
81
|
+
"lerna": "^5.4.2",
|
|
82
82
|
"prettier": "^2.7.1",
|
|
83
|
-
"prettier-plugin-organize-imports": "^3.0.
|
|
83
|
+
"prettier-plugin-organize-imports": "^3.0.3",
|
|
84
84
|
"rimraf": "^3.0.2",
|
|
85
85
|
"semantic-release": "^19.0.3",
|
|
86
|
-
"ts-jest": "^28.0.
|
|
86
|
+
"ts-jest": "^28.0.8",
|
|
87
87
|
"ts-node": "^10.9.1",
|
|
88
88
|
"typescript": "4.7.4"
|
|
89
89
|
},
|
|
@@ -64,6 +64,7 @@ export class StaticSite extends CommonConstruct {
|
|
|
64
64
|
this.createSiteCloudfrontFunction()
|
|
65
65
|
this.resolveSiteFunctionAssociations()
|
|
66
66
|
this.createSiteDistribution()
|
|
67
|
+
this.invalidateDistributionCache()
|
|
67
68
|
this.createSiteRouteAssets()
|
|
68
69
|
this.deploySite()
|
|
69
70
|
}
|
|
@@ -174,6 +175,21 @@ export class StaticSite extends CommonConstruct {
|
|
|
174
175
|
)
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
180
|
+
* @protected
|
|
181
|
+
*/
|
|
182
|
+
protected invalidateDistributionCache() {
|
|
183
|
+
if (this.props.siteCacheInvalidationDockerFilePath) {
|
|
184
|
+
this.cloudFrontManager.invalidateCache(
|
|
185
|
+
`${this.id}-cache-invalidation`,
|
|
186
|
+
this,
|
|
187
|
+
this.props.siteCacheInvalidationDockerFilePath,
|
|
188
|
+
this.siteDistribution.distributionId
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
177
193
|
/**
|
|
178
194
|
* @summary Method to create route53 records for static site
|
|
179
195
|
* @protected
|
|
@@ -180,6 +180,7 @@ export class CloudFrontManager {
|
|
|
180
180
|
* @param {s3.IBucket?} logBucket
|
|
181
181
|
* @param {acm.ICertificate?} certificate
|
|
182
182
|
* @param {cloudfront.FunctionAssociation?} defaultFunctionAssociations
|
|
183
|
+
* @param {cloudfront.IResponseHeadersPolicy?} responseHeadersPolicy
|
|
183
184
|
*/
|
|
184
185
|
public createDistributionWithHttpOrigin(
|
|
185
186
|
id: string,
|
|
@@ -189,7 +190,8 @@ export class CloudFrontManager {
|
|
|
189
190
|
domainNames: string[],
|
|
190
191
|
logBucket?: s3.IBucket,
|
|
191
192
|
certificate?: acm.ICertificate,
|
|
192
|
-
defaultFunctionAssociations?: cloudfront.FunctionAssociation[]
|
|
193
|
+
defaultFunctionAssociations?: cloudfront.FunctionAssociation[],
|
|
194
|
+
responseHeadersPolicy?: cloudfront.IResponseHeadersPolicy
|
|
193
195
|
) {
|
|
194
196
|
const distribution = new cloudfront.Distribution(scope, `${id}`, {
|
|
195
197
|
certificate: certificate,
|
|
@@ -200,6 +202,7 @@ export class CloudFrontManager {
|
|
|
200
202
|
originRequestPolicy: props.defaultBehavior ? props.defaultBehavior.originRequestPolicy : undefined,
|
|
201
203
|
functionAssociations: defaultFunctionAssociations ?? undefined,
|
|
202
204
|
viewerProtocolPolicy: props.defaultBehavior ? props.defaultBehavior.viewerProtocolPolicy : undefined,
|
|
205
|
+
responseHeadersPolicy: responseHeadersPolicy ?? undefined,
|
|
203
206
|
},
|
|
204
207
|
additionalBehaviors: props.additionalBehaviors,
|
|
205
208
|
defaultRootObject: props.defaultRootObject,
|
|
@@ -86,6 +86,7 @@ export interface SiteWithEcsBackendProps extends CommonStackProps {
|
|
|
86
86
|
* @subcategory Properties
|
|
87
87
|
*/
|
|
88
88
|
export interface StaticSiteProps extends CommonStackProps {
|
|
89
|
+
siteCacheInvalidationDockerFilePath?: string
|
|
89
90
|
siteCreateAltARecord: boolean
|
|
90
91
|
siteCertificate: AcmProps
|
|
91
92
|
siteBucket: S3BucketProps
|