Skip to content

fix(s3): handle NoSuchBucket error during notification cleanup#35388

Closed
maxc01 wants to merge 1 commit intoaws:mainfrom
maxc01:fix/s3-notification-deletion-error
Closed

fix(s3): handle NoSuchBucket error during notification cleanup#35388
maxc01 wants to merge 1 commit intoaws:mainfrom
maxc01:fix/s3-notification-deletion-error

Conversation

@maxc01
Copy link
Copy Markdown

@maxc01 maxc01 commented Sep 1, 2025

Issue # (if applicable)

Closes #35352.

Reason for this change

When deleting a CloudFormation stack containing S3 bucket notifications, if the bucket is deleted before the notification cleanup runs (due to timing or manual deletion), the custom resource fails with a NoSuchBucket error, causing the entire stack deletion to fail. This prevents users from properly cleaning up their stacks.

Description of changes

Added error handling in the Python custom resource handler (notifications-resource-handler/index.py) to catch ClientError exceptions with NoSuchBucket error code during deletion operations. When this error occurs during a DELETE request, it's treated as expected behavior rather than a failure, allowing the stack deletion to proceed normally.

Describe any new or updated permissions being added

No new IAM permissions are being added. The fix only adds error handling logic to existing operations.

Description of how you validated changes

  • Added unit tests covering both RemovalPolicy.RETAIN and RemovalPolicy.DESTROY scenarios
  • Added integration test that creates buckets with both removal policies and validates notification cleanup works without errors
  • Verified existing unit tests continue to pass
  • The fix handles the error gracefully without changing the expected behavior for normal operations

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Sep 1, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team September 1, 2025 14:29
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Sep 1, 2025
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch from 84f4b26 to ab96438 Compare September 1, 2025 14:36
@maxc01 maxc01 changed the title fix(aws-s3): handle NoSuchBucket error during notification cleanup fix(s3): handle NoSuchBucket error during notification cleanup Sep 1, 2025
@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch from ab96438 to e9f906a Compare September 1, 2025 14:41
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 1, 2025 14:41

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch 2 times, most recently from 03f0ee7 to 5834e15 Compare September 1, 2025 14:59
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch from 5834e15 to 01c9889 Compare September 1, 2025 15:20
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 1, 2025 15:22

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch 4 times, most recently from 44ffa90 to 8b42f39 Compare September 2, 2025 19:17
Fixes aws#35352

When a bucket is deleted before its notifications during stack deletion,
the custom resource handler now gracefully handles NoSuchBucket errors
instead of failing the entire stack deletion.

Changes:
- Add error handling for NoSuchBucket in Python custom resource handler
- Add unit tests for RETAIN and DESTROY removal policies
- Add integration test covering both scenarios
@maxc01 maxc01 force-pushed the fix/s3-notification-deletion-error branch from 8b42f39 to 71903e0 Compare September 2, 2025 19:39
@maxc01 maxc01 closed this Sep 3, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

addEventNotification causes "NoSuchBucket" errors during stack deletion regardless of bucket RemovalPolicy

2 participants