Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom-resource-handlers/aws-s3/auto-delete-objects-handler: Object locked objects prevent cdk destroy #32147

Open
1 task
aaronmills1 opened this issue Nov 15, 2024 · 0 comments
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@aaronmills1
Copy link

aaronmills1 commented Nov 15, 2024

Describe the bug

When an s3 bucket is created with object lock governance and the s3 bucket is set for removal cdk destroy fails. This happens even when the role has permissions to bypassgovernancelock

This is because in the auto-delete-objects-handler the s3 delete objects is called without BypassGovernanceRetention

Current: await s3.deleteObjects({ Bucket: bucketName, Delete: { Objects: records } });

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

I expect for the cdk destroy to remove the governed objects provided the role has the necessary permissions

Current Behavior

The cdk destroy fails and the stack reverts back to its previous state

Reproduction Steps

    import * as s3 from 'aws-cdk-lib/aws-s3'
    import * as cdk from 'aws-cdk-lib'
    new s3.Bucket(scope, 'testID', {
          autoDeleteObjects: true,
          removalPolicy: cdk.RemovalPolicy.DESTROY,
          versioned: true,
          objectLockDefaultRetention: s3.ObjectLockRetention.governance(
            cdk.Duration.days(7)
          )
        })

Add some objects, then run cdk destroy

Possible Solution

await s3.deleteObjects({ Bucket: bucketName, Delete: { Objects: records }, BypassGovernanceRetention: true });

The above will work for governed objects however will fail for non object locked objects. For this reason a combination of the two will need to be used

Additional Information/Context

No response

CDK CLI Version

2.160.0 (build 7a8ae02)

Framework Version

No response

Node.js Version

v21.7.1

OS

MacOS 14.7.1

Language

TypeScript

Language Version

No response

Other information

No response

@aaronmills1 aaronmills1 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant