From 3bf4acffe2d76a9edc03a9eea2bb12b1f37668c4 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 23 May 2024 13:39:20 +0930 Subject: [PATCH 1/4] DO-1660: specify viewer protocol policy --- packages/static-hosting/lib/static-hosting.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index 0c4b2e51..3f573250 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -519,6 +519,7 @@ export class StaticHosting extends Construct { for (const path of props.remapPaths) { additionalBehaviors[path.from] = { origin: s3Origin, + viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, edgeLambdas: this.createRemapBehavior(path.from, path.to), }; } From 5605e06270e8d8ad01617a85b4d1c5b68971d3e5 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 23 May 2024 13:39:49 +0930 Subject: [PATCH 2/4] DO-1661: make "to" path in remap optional --- packages/static-hosting/lib/static-hosting.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index 3f573250..19323e01 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -143,6 +143,7 @@ export interface StaticHostingProps { * Paths to remap on the default behaviour. For example you might remap deployed_sitemap.xml -> sitemap.xml * Created a behaviour in CloudFront to handle the remap. If the paths are different * it will also deploy a Lambda@Edge function to perform the required remap. + * The "to" path is optional, and the Lambda@Edge function will not be deployed if not provided. * * @default undefined */ @@ -276,7 +277,7 @@ export interface StaticHostingProps { interface remapPath { from: string; - to: string; + to?: string; } export interface ResponseHeaderMappings { @@ -611,12 +612,12 @@ export class StaticHosting extends Construct { } } - private createRemapBehavior(from: string, to: string): EdgeLambda[] { + private createRemapBehavior(from: string, to?: string): EdgeLambda[] { const lambdas: EdgeLambda[] = []; // If the remap is to a different path, create a Lambda@Edge function to handle this // Remove special characters from path - if (from.replace(/\*$/, "") !== to) { + if (from.replace(/\*$/, "") !== to && to) { const id = from.replace(/[&/\\#,+()$~%'":*?<>{}]/g, "-"); const remapFunction = new PathRemapFunction( From f34290a49648a3c0a66937488d44b482b5fa02a0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 23 May 2024 13:40:09 +0930 Subject: [PATCH 3/4] DO-1660: DO-1661: version upgrade to 2.3.4 --- packages/static-hosting/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/static-hosting/package.json b/packages/static-hosting/package.json index ecda9659..4bbfcd06 100644 --- a/packages/static-hosting/package.json +++ b/packages/static-hosting/package.json @@ -1,6 +1,6 @@ { "name": "@aligent/cdk-static-hosting", - "version": "2.3.1", + "version": "2.3.4", "main": "index.js", "license": "GPL-3.0-only", "homepage": "https://github.com/aligent/aws-cdk-static-hosting-stack#readme", From 30512db8f6e4c44faacde06546f7016a739d66fd Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 23 May 2024 13:51:34 +0930 Subject: [PATCH 4/4] DO-1661: let parameter presence evaluated first --- packages/static-hosting/lib/static-hosting.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index 19323e01..b18e6454 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -617,7 +617,7 @@ export class StaticHosting extends Construct { // If the remap is to a different path, create a Lambda@Edge function to handle this // Remove special characters from path - if (from.replace(/\*$/, "") !== to && to) { + if (to && from.replace(/\*$/, "") !== to) { const id = from.replace(/[&/\\#,+()$~%'":*?<>{}]/g, "-"); const remapFunction = new PathRemapFunction(