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', () => {