From 5ab4c933a8f7b8e3f65ba8c8ae23ead57d188372 Mon Sep 17 00:00:00 2001 From: c19yamamoto <63878044+c19yamamoto@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:17:54 +0000 Subject: [PATCH 1/4] Initial plan From 66cc6a7add5b409d7467382f230daec027694128 Mon Sep 17 00:00:00 2001 From: c19yamamoto <63878044+c19yamamoto@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:21:05 +0000 Subject: [PATCH 2/4] Retain static website bucket Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- cdk/lib/construct/static-website-construct.ts | 3 +- cdk/test/__snapshots__/cdk.test.ts.snap | 124 +----------------- cdk/test/cdk.test.ts | 5 +- 3 files changed, 6 insertions(+), 126 deletions(-) diff --git a/cdk/lib/construct/static-website-construct.ts b/cdk/lib/construct/static-website-construct.ts index e403bdb..90ec910 100644 --- a/cdk/lib/construct/static-website-construct.ts +++ b/cdk/lib/construct/static-website-construct.ts @@ -25,8 +25,7 @@ export class StaticWebsite extends Construct { this.cloudFrontToS3 = new CloudFrontToS3(this, 'CloudFrontToS3', { bucketProps: { bucketName: `${props.domainName}-static-website`, - removalPolicy: RemovalPolicy.DESTROY, - autoDeleteObjects: true, + removalPolicy: RemovalPolicy.RETAIN, }, cloudFrontDistributionProps: { domainNames: [props.domainName], diff --git a/cdk/test/__snapshots__/cdk.test.ts.snap b/cdk/test/__snapshots__/cdk.test.ts.snap index f585045..a826189 100644 --- a/cdk/test/__snapshots__/cdk.test.ts.snap +++ b/cdk/test/__snapshots__/cdk.test.ts.snap @@ -191,64 +191,6 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` }, "Type": "AWS::IAM::Policy", }, - "CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F": { - "DependsOn": [ - "CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092", - ], - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", - }, - "S3Key": "6dba3da2af96b69a187d689b326e5272b9abc8671c0427845a8bed243e02877d.zip", - }, - "Description": { - "Fn::Join": [ - "", - [ - "Lambda function for auto-deleting objects in ", - { - "Ref": "WebsiteCloudFrontToS3S3Bucket18AD4248", - }, - " S3 bucket.", - ], - ], - }, - "Handler": "index.handler", - "MemorySize": 128, - "Role": { - "Fn::GetAtt": [ - "CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092", - "Arn", - ], - }, - "Runtime": "nodejs24.x", - "Timeout": 900, - }, - "Type": "AWS::Lambda::Function", - }, - "CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092": { - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com", - }, - }, - ], - "Version": "2012-10-17", - }, - "ManagedPolicyArns": [ - { - "Fn::Sub": "arn:\${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - }, - ], - }, - "Type": "AWS::IAM::Role", - }, "WebsiteAliasRecord373AF9B6": { "Properties": { "AliasTarget": { @@ -450,7 +392,7 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` "Type": "AWS::S3::BucketPolicy", }, "WebsiteCloudFrontToS3S3Bucket18AD4248": { - "DeletionPolicy": "Delete", + "DeletionPolicy": "Retain", "Properties": { "BucketEncryption": { "ServerSideEncryptionConfiguration": [ @@ -482,10 +424,6 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` "RestrictPublicBuckets": true, }, "Tags": [ - { - "Key": "aws-cdk:auto-delete-objects", - "Value": "true", - }, { "Key": "aws-cdk:cr-owned:67bfaeff", "Value": "true", @@ -496,26 +434,7 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` }, }, "Type": "AWS::S3::Bucket", - "UpdateReplacePolicy": "Delete", - }, - "WebsiteCloudFrontToS3S3BucketAutoDeleteObjectsCustomResourceD5BD2FF4": { - "DeletionPolicy": "Delete", - "DependsOn": [ - "WebsiteCloudFrontToS3S3BucketPolicy59EB757C", - ], - "Properties": { - "BucketName": { - "Ref": "WebsiteCloudFrontToS3S3Bucket18AD4248", - }, - "ServiceToken": { - "Fn::GetAtt": [ - "CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F", - "Arn", - ], - }, - }, - "Type": "Custom::S3AutoDeleteObjects", - "UpdateReplacePolicy": "Delete", + "UpdateReplacePolicy": "Retain", }, "WebsiteCloudFrontToS3S3BucketPolicy59EB757C": { "Metadata": { @@ -568,45 +487,6 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` }, ], }, - { - "Action": [ - "s3:PutBucketPolicy", - "s3:GetBucket*", - "s3:List*", - "s3:DeleteObject*", - ], - "Effect": "Allow", - "Principal": { - "AWS": { - "Fn::GetAtt": [ - "CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092", - "Arn", - ], - }, - }, - "Resource": [ - { - "Fn::GetAtt": [ - "WebsiteCloudFrontToS3S3Bucket18AD4248", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "WebsiteCloudFrontToS3S3Bucket18AD4248", - "Arn", - ], - }, - "/*", - ], - ], - }, - ], - }, { "Action": "s3:GetObject", "Condition": { diff --git a/cdk/test/cdk.test.ts b/cdk/test/cdk.test.ts index 03fce73..c66ffa3 100644 --- a/cdk/test/cdk.test.ts +++ b/cdk/test/cdk.test.ts @@ -71,8 +71,9 @@ test('creates a private S3 origin with the expected website bucket settings', () ); expect(websiteBucket).toBeDefined(); - expect(websiteBucket?.DeletionPolicy).toBe('Delete'); - expect(websiteBucket?.UpdateReplacePolicy).toBe('Delete'); + expect(websiteBucket?.DeletionPolicy).toBe('Retain'); + expect(websiteBucket?.UpdateReplacePolicy).toBe('Retain'); + template.resourceCountIs('Custom::S3AutoDeleteObjects', 0); }); test('configures HTTPS CloudFront delivery and Route53 aliasing', () => { From dc48668ee3a8bb0f2465cc498dc8b77119289bf4 Mon Sep 17 00:00:00 2001 From: c19yamamoto <63878044+c19yamamoto@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:20:00 +0000 Subject: [PATCH 3/4] Disable deprecated CloudFront logging bucket Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- cdk/lib/construct/static-website-construct.ts | 1 + cdk/test/__snapshots__/cdk.test.ts.snap | 88 ------------------- cdk/test/cdk.test.ts | 13 ++- 3 files changed, 13 insertions(+), 89 deletions(-) diff --git a/cdk/lib/construct/static-website-construct.ts b/cdk/lib/construct/static-website-construct.ts index 90ec910..27afe81 100644 --- a/cdk/lib/construct/static-website-construct.ts +++ b/cdk/lib/construct/static-website-construct.ts @@ -31,6 +31,7 @@ export class StaticWebsite extends Construct { domainNames: [props.domainName], certificate: props.certificate, defaultRootObject: 'index.html', + enableLogging: false, }, insertHttpSecurityHeaders: false, logS3AccessLogs: false, diff --git a/cdk/test/__snapshots__/cdk.test.ts.snap b/cdk/test/__snapshots__/cdk.test.ts.snap index a826189..4e606ec 100644 --- a/cdk/test/__snapshots__/cdk.test.ts.snap +++ b/cdk/test/__snapshots__/cdk.test.ts.snap @@ -242,14 +242,6 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` "Enabled": true, "HttpVersion": "http2", "IPV6Enabled": true, - "Logging": { - "Bucket": { - "Fn::GetAtt": [ - "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", - "RegionalDomainName", - ], - }, - }, "Origins": [ { "DomainName": { @@ -311,86 +303,6 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` }, "Type": "AWS::CloudFront::OriginAccessControl", }, - "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9": { - "DeletionPolicy": "Retain", - "Properties": { - "AccessControl": "LogDeliveryWrite", - "BucketEncryption": { - "ServerSideEncryptionConfiguration": [ - { - "ServerSideEncryptionByDefault": { - "SSEAlgorithm": "AES256", - }, - }, - ], - }, - "OwnershipControls": { - "Rules": [ - { - "ObjectOwnership": "ObjectWriter", - }, - ], - }, - "PublicAccessBlockConfiguration": { - "BlockPublicAcls": true, - "BlockPublicPolicy": true, - "IgnorePublicAcls": true, - "RestrictPublicBuckets": true, - }, - "VersioningConfiguration": { - "Status": "Enabled", - }, - }, - "Type": "AWS::S3::Bucket", - "UpdateReplacePolicy": "Retain", - }, - "WebsiteCloudFrontToS3CloudfrontLoggingBucketPolicy5BF04B0B": { - "Properties": { - "Bucket": { - "Ref": "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", - }, - "PolicyDocument": { - "Statement": [ - { - "Action": "s3:*", - "Condition": { - "Bool": { - "aws:SecureTransport": "false", - }, - }, - "Effect": "Deny", - "Principal": { - "AWS": "*", - }, - "Resource": [ - { - "Fn::GetAtt": [ - "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", - "Arn", - ], - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::GetAtt": [ - "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", - "Arn", - ], - }, - "/*", - ], - ], - }, - ], - }, - ], - "Version": "2012-10-17", - }, - }, - "Type": "AWS::S3::BucketPolicy", - }, "WebsiteCloudFrontToS3S3Bucket18AD4248": { "DeletionPolicy": "Retain", "Properties": { diff --git a/cdk/test/cdk.test.ts b/cdk/test/cdk.test.ts index c66ffa3..819c6b7 100644 --- a/cdk/test/cdk.test.ts +++ b/cdk/test/cdk.test.ts @@ -52,7 +52,7 @@ beforeAll(() => { test('creates a private S3 origin with the expected website bucket settings', () => { const template = websiteTemplate; - template.resourceCountIs('AWS::S3::Bucket', 2); + template.resourceCountIs('AWS::S3::Bucket', 1); template.hasResourceProperties('AWS::S3::Bucket', { BucketName: `${domainName}-static-website`, PublicAccessBlockConfiguration: { @@ -100,6 +100,17 @@ test('configures HTTPS CloudFront delivery and Route53 aliasing', () => { }); }); +test('disables CloudFront access logging', () => { + const resources = websiteTemplate.toJSON().Resources as Record; + const distribution = Object.values(resources).find( + (resource) => resource.Type === 'AWS::CloudFront::Distribution', + ); + + expect(distribution?.Properties?.DistributionConfig).not.toHaveProperty( + 'Logging', + ); +}); + test('invalidates CloudFront after deploying the static export', () => { const resources = websiteTemplate.toJSON().Resources as Record; const deployments = Object.values(resources).filter( From f1eef18e7b0117cdec0bb543688548646bd4fd55 Mon Sep 17 00:00:00 2001 From: c19yamamoto <63878044+c19yamamoto@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:26:01 +0000 Subject: [PATCH 4/4] Remove explicit CloudFront logging override Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- cdk/lib/construct/static-website-construct.ts | 1 - cdk/test/__snapshots__/cdk.test.ts.snap | 88 +++++++++++++++++++ cdk/test/cdk.test.ts | 13 +-- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/cdk/lib/construct/static-website-construct.ts b/cdk/lib/construct/static-website-construct.ts index 27afe81..90ec910 100644 --- a/cdk/lib/construct/static-website-construct.ts +++ b/cdk/lib/construct/static-website-construct.ts @@ -31,7 +31,6 @@ export class StaticWebsite extends Construct { domainNames: [props.domainName], certificate: props.certificate, defaultRootObject: 'index.html', - enableLogging: false, }, insertHttpSecurityHeaders: false, logS3AccessLogs: false, diff --git a/cdk/test/__snapshots__/cdk.test.ts.snap b/cdk/test/__snapshots__/cdk.test.ts.snap index 4e606ec..a826189 100644 --- a/cdk/test/__snapshots__/cdk.test.ts.snap +++ b/cdk/test/__snapshots__/cdk.test.ts.snap @@ -242,6 +242,14 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` "Enabled": true, "HttpVersion": "http2", "IPV6Enabled": true, + "Logging": { + "Bucket": { + "Fn::GetAtt": [ + "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", + "RegionalDomainName", + ], + }, + }, "Origins": [ { "DomainName": { @@ -303,6 +311,86 @@ exports[`matches the synthesized CloudFormation template snapshot 1`] = ` }, "Type": "AWS::CloudFront::OriginAccessControl", }, + "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9": { + "DeletionPolicy": "Retain", + "Properties": { + "AccessControl": "LogDeliveryWrite", + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256", + }, + }, + ], + }, + "OwnershipControls": { + "Rules": [ + { + "ObjectOwnership": "ObjectWriter", + }, + ], + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true, + }, + "VersioningConfiguration": { + "Status": "Enabled", + }, + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "WebsiteCloudFrontToS3CloudfrontLoggingBucketPolicy5BF04B0B": { + "Properties": { + "Bucket": { + "Ref": "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", + }, + "PolicyDocument": { + "Statement": [ + { + "Action": "s3:*", + "Condition": { + "Bool": { + "aws:SecureTransport": "false", + }, + }, + "Effect": "Deny", + "Principal": { + "AWS": "*", + }, + "Resource": [ + { + "Fn::GetAtt": [ + "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", + "Arn", + ], + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "WebsiteCloudFrontToS3CloudfrontLoggingBucketF02A63E9", + "Arn", + ], + }, + "/*", + ], + ], + }, + ], + }, + ], + "Version": "2012-10-17", + }, + }, + "Type": "AWS::S3::BucketPolicy", + }, "WebsiteCloudFrontToS3S3Bucket18AD4248": { "DeletionPolicy": "Retain", "Properties": { diff --git a/cdk/test/cdk.test.ts b/cdk/test/cdk.test.ts index 819c6b7..c66ffa3 100644 --- a/cdk/test/cdk.test.ts +++ b/cdk/test/cdk.test.ts @@ -52,7 +52,7 @@ beforeAll(() => { test('creates a private S3 origin with the expected website bucket settings', () => { const template = websiteTemplate; - template.resourceCountIs('AWS::S3::Bucket', 1); + template.resourceCountIs('AWS::S3::Bucket', 2); template.hasResourceProperties('AWS::S3::Bucket', { BucketName: `${domainName}-static-website`, PublicAccessBlockConfiguration: { @@ -100,17 +100,6 @@ test('configures HTTPS CloudFront delivery and Route53 aliasing', () => { }); }); -test('disables CloudFront access logging', () => { - const resources = websiteTemplate.toJSON().Resources as Record; - const distribution = Object.values(resources).find( - (resource) => resource.Type === 'AWS::CloudFront::Distribution', - ); - - expect(distribution?.Properties?.DistributionConfig).not.toHaveProperty( - 'Logging', - ); -}); - test('invalidates CloudFront after deploying the static export', () => { const resources = websiteTemplate.toJSON().Resources as Record; const deployments = Object.values(resources).filter(