Summary
sst remove fails when a StaticSite asset bucket is already absent because the internal BucketFiles resource treats S3 NoSuchBucket as a fatal deletion error.
Deletion should be idempotent when the bucket and all managed objects no longer exist.
Environment
- SST: 4.14.3
- Confirmed still present in SST 4.17.1 and current
dev
- AWS region: eu-north-1
- Platform: macOS arm64
- Component:
sst.aws.StaticSite
Reproduction
- Deploy an
sst.aws.StaticSite.
- Delete its generated asset bucket externally, or interrupt a removal after the bucket has been deleted.
- Run
sst remove.
- The
BucketFiles resource attempts to delete its recorded objects from the missing bucket.
Actual behavior
Web sst:aws:StaticSite -> WebAssetFiles sst:aws:BucketFiles
operation error S3: DeleteObject
StatusCode: 404
NoSuchBucket: The specified bucket does not exist
The stage remains partially removed. Recovery requires manually removing the BucketFiles dynamic resource from state and rerunning sst remove.
Expected behavior
BucketFiles.Delete should treat NoSuchBucket as successful deletion. Other S3 errors should remain fatal.
Source review
Current dev still delegates deletion directly to purge:
https://github.com/anomalyco/sst/blob/dev/pkg/server/resource/aws-bucket-files.go
func (r *BucketFiles) Delete(...) error {
// ...
return r.purge(s3Client, input.Outs.BucketName, nil, input.Outs.Files)
}
purge returns the first DeleteObject error without classifying NoSuchBucket. Since purge is also used during updates, the idempotent handling should be limited to Delete.
Suggested fix / PR
- Detect typed
*s3types.NoSuchBucket errors in BucketFiles.Delete.
- Defensively recognize a Smithy
APIError with code NoSuchBucket.
- Return success only from the delete lifecycle path.
- Keep missing buckets fatal during create/update.
- Avoid a preliminary
HeadBucket, which would add a request and retain a check/delete race.
Suggested tests:
- Missing bucket during delete returns success.
- Missing bucket during update remains an error.
AccessDenied and other S3 errors remain errors.
- Existing-bucket deletion remains unchanged.
Summary
sst removefails when a StaticSite asset bucket is already absent because the internalBucketFilesresource treats S3NoSuchBucketas a fatal deletion error.Deletion should be idempotent when the bucket and all managed objects no longer exist.
Environment
devsst.aws.StaticSiteReproduction
sst.aws.StaticSite.sst remove.BucketFilesresource attempts to delete its recorded objects from the missing bucket.Actual behavior
The stage remains partially removed. Recovery requires manually removing the
BucketFilesdynamic resource from state and rerunningsst remove.Expected behavior
BucketFiles.Deleteshould treatNoSuchBucketas successful deletion. Other S3 errors should remain fatal.Source review
Current
devstill delegates deletion directly topurge:https://github.com/anomalyco/sst/blob/dev/pkg/server/resource/aws-bucket-files.go
purgereturns the firstDeleteObjecterror without classifyingNoSuchBucket. Sincepurgeis also used during updates, the idempotent handling should be limited toDelete.Suggested fix / PR
*s3types.NoSuchBucketerrors inBucketFiles.Delete.APIErrorwith codeNoSuchBucket.HeadBucket, which would add a request and retain a check/delete race.Suggested tests:
AccessDeniedand other S3 errors remain errors.