{"record":{"id":"18727bca7c5b7d20","repo":"anomalyco/sst","slug":"failed-to-delete-s3-bucket-s-w","errorCode":null,"errorMessage":"failed to delete S3 bucket %s: %w","messagePattern":"failed to delete S3 bucket (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/project/provider/aws.go","lineNumber":457,"sourceCode":"\t\t\t\t\tDelete: &s3types.Delete{Objects: objectIdentifiers},\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\tif listObjectsOutput.IsTruncated == nil || !*listObjectsOutput.IsTruncated {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcontinuationToken = listObjectsOutput.NextContinuationToken\n\t\t\t}\n\n\t\t\t// Remove the previously created S3 bucket\n\t\t\t_, err := s3Client.DeleteBucket(ctx, &s3.DeleteBucketInput{\n\t\t\t\tBucket: aws.String(data.Asset),\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\tif !strings.Contains(err.Error(), \"NoSuchBucket\") {\n\t\t\t\t\treturn fmt.Errorf(\"failed to delete S3 bucket %s: %w\", data.Asset, err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Assign the new bucket name\n\t\t\tdata.Asset = value.Bucket\n\t\t}\n\n\t\t// Remove the SSM parameter\n\t\t_, err = ssmClient.DeleteParameter(ctx, &ssm.DeleteParameterInput{\n\t\t\tName: aws.String(ssmKey),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to delete SSM parameter %s: %w\", ssmKey, err)\n\t\t}\n\n\t\treturn nil\n\t},\n","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/project/provider/aws.go#L439-L475","documentation":"While migrating from the old bootstrap, SST empties the legacy asset bucket and deletes it. If `s3:DeleteBucket` fails for any reason other than `NoSuchBucket`, this error wraps the AWS failure. Deletion typically fails when the bucket still contains objects (including versioned ones) or permissions are missing.","triggerScenarios":"The legacy bucket is non-empty (versioning enabled leaves delete markers/versions the plain DeleteObjects pass does not remove), the credentials lack `s3:DeleteBucket`, or the bucket has a deny policy / region mismatch.","commonSituations":"Upgrading SST across the bootstrap change with a long-lived asset bucket that has versioning or leftover objects; SCP or bucket policy denying deletes.","solutions":["Empty the legacy asset bucket manually (`aws s3 rm s3://<bucket> --recursive`, and remove all object versions if versioned) then re-run `sst deploy`","Check the bucket policy for an explicit Deny on `s3:DeleteBucket` (e.g. the SSL-enforcement policy) and the IAM/SCP permissions of the deploy role","Verify the bucket region matches the configured AWS region"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"aws s3api list-object-versions --bucket <legacy-asset-bucket> --max-items 5  # ensure bucket is fully empty before deploy","typeGuard":null,"tryCatchPattern":"err := sstDeploy(ctx)\nvar delErr *s3types.NoSuchBucket\nif err != nil && strings.Contains(err.Error(), \"failed to delete S3 bucket\") {\n    // empty all versions + delete markers, then retry\n    purgeAllVersions(\"legacy-asset-bucket\")\n    err = sstDeploy(ctx)\n}","preventionTips":["Fully empty legacy asset buckets (including versions) before upgrading SST","Grant deploy role s3:DeleteBucket on sst-* buckets","Check bucket policies don't deny s3:DeleteBucket"],"tags":["aws","s3","bucket-deletion","bootstrap-migration"],"backgroundTag":"s3-bucket-not-empty","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}