From 25656459b7117879d9ff6774ff53d1fa9cd1a503 Mon Sep 17 00:00:00 2001 From: Gowri Date: Tue, 26 Sep 2023 19:10:44 +0930 Subject: [PATCH] DO-1531: make default behaviour lambdas optional * add viewer protocol policy to redirect http to https --- packages/static-hosting/lib/static-hosting.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index 4eaa977b..1299c0f3 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -90,7 +90,7 @@ export interface StaticHostingProps { responseHeadersPolicies?: ResponseHeaderMappings; additionalBehaviors?: Record; errorResponsePagePath?: string; - defaultBehaviorEdgeLambdas: EdgeLambda[]; + defaultBehaviorEdgeLambdas?: EdgeLambda[]; /** * After switching constructs, you need to maintain the same logical ID @@ -147,6 +147,7 @@ export class StaticHosting extends Construct { const enableStaticFileRemap = props.enableStaticFileRemap !== false; const defaultRootObject = props.defaultRootObject ?? "/index.html"; const errorResponsePagePath = props.errorResponsePagePath ?? "/index.html"; + const defaultBehaviorEdgeLambdas = props.defaultBehaviorEdgeLambdas ?? []; const disableCSP = props.disableCSP === true; const domainNames: Array = props.extraDistributionCnames @@ -295,7 +296,7 @@ export class StaticHosting extends Construct { const defaultBehavior: Writeable = { origin: s3Origin, viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, - edgeLambdas: props.defaultBehaviorEdgeLambdas, + edgeLambdas: defaultBehaviorEdgeLambdas, originRequestPolicy: originRequestPolicy, cachePolicy: originCachePolicy, responseHeadersPolicy: responseHeadersPolicy, @@ -319,7 +320,10 @@ export class StaticHosting extends Construct { if (enableStaticFileRemap) { for (const path of this.staticFiles) { - additionalBehaviors[`*.${path}`] = { origin: s3Origin }; + additionalBehaviors[`*.${path}`] = { + origin: s3Origin, + viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + }; } }