Reputation: 785
I'm using the web interface of Amazon's S3, and when I right-click a folder X and choose Delete, X seems to be deleted. Then when I refresh the interface, X may either disappear or remain; if I keep clicking refresh, the folder is either missing or present. Is this a bug, or am I doing something wrong? The folder is still present, as far as I can tell; one of my EMR jobs complains that the output folder X still exists.
Upvotes: 30
Views: 32814
Reputation: 3534
If you're having trouble fully deleting an empty folder in an S3 bucket that has versioning turned on (i.e. removing all trace of the folder, including in 'Show versions' mode), you can usually get around it by deleting the folder's delete marker(s) using the API/CLI:
$ aws s3api list-object-versions --bucket YOUR-BUCKET --prefix PATH-TO-YOUR-FOLDER
{
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "YOUR-ACCOUNT-NAME",
"ID": "YOUR-ACCOUNT-CANONICAL-ID"
},
"Key": "PATH-TO-YOUR-FOLDER/",
"VersionId": "UNIQUE-VERSION-ID",
"IsLatest": true,
"LastModified": "2022-12-09T07:18:57+00:00"
}
]
}
$ aws s3api delete-objects --bucket YOUR-BUCKET --delete 'Objects=[{Key=PATH-TO-YOUR-FOLDER/,VersionId=UNIQUE-VERSION-ID}]'
{
"Deleted": [
{
"Key": "PATH-TO-YOUR-FOLDER/",
"VersionId": "UNIQUE-VERSION-ID",
"DeleteMarker": true,
"DeleteMarkerVersionId": "UNIQUE-VERSION-ID"
}
]
}
Upvotes: 1
Reputation: 16806
I encountered this issue when I was unable to delete an empty folder from an S3 bucket that had Versioning enabled.
I was able to delete the empty folder by using the "empty bucket configuration" from the S3 Buckets listing:
Select the bucket you'd like to empty, and click the Delete
button:
AWS warns you that the bucket isn't empty, and offers a link to use the empty bucket configuration
. Click the link:
Proceed through this screen by typing permanently delete
to delete all the objects in this bucket:
You should then be able to verify that your S3 bucket is truly empty.
Upvotes: 5
Reputation: 553
Try delete with another account, like administrator account. For me it works only with this method.
Upvotes: 0
Reputation: 20523
I have the same problem that I cant delete a s3 bucket, with the message "An error occurred (AccessDenied) when calling the DeleteBucket operation: Access Denied"
After a while, I delete the bucket policy in tab "permission" button "bucket policy" and It worked like a charm, with:
aws s3 rb s3://elasticbeanstalk-us-west-..../ --force
I hope this help! Is another option Pablo
Upvotes: 1
Reputation: 779
I had the same problem and didn't have access to the amazon console but I could delete it with this Java code
AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials);
ObjectListing objectListing = amazonS3Client.listObjects("bucketName", "prefix");
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest("bucketName");
List<DeleteObjectsRequest.KeyVersion> keysToDelete = new ArrayList<>();
objectListing.getObjectSummaries().forEach(s3ObjectSummary -> {
keysToDelete.add(new DeleteObjectsRequest.KeyVersion(s3ObjectSummary.getKey()));
});
deleteObjectsRequest.setKeys(keysToDelete);
amazonS3Client.deleteObjects(deleteObjectsRequest);
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.7.4</version>
</dependency>
Upvotes: 0
Reputation: 11
had an "elastic-bean-stalk" bucket and had to delete "bucket policy" before it would delete.
pitney
Upvotes: 0
Reputation: 1744
As of March 2017 the AWS Console UI has changed and you can no longer enter a 'versioning mode' described in my old post.
It seems now folder with versioned files can be deleted freely without restriction.
If this is not the case please drop a comment so I can correct this post.
Previous Version of AWS Console
If you are using the AWS Management Console and you have versioning turned ON, you must be in 'versioning mode' to delete the folder. You enter 'versioning mode' by going to the top of the page and next to where it says 'Versions:' select the Show button. Then you can proceed to right-click and delete your folder. Hope this helps someone.
Upvotes: 6
Reputation: 2086
Try use the new S3 console. The delete feature works for folders.
Upvotes: -2
Reputation: 30760
Tried the same as Kristoffer's answer, but CUT/PASTE to another folder made the new folder to not be deletable.
Further hacking: create a new temporary bucket. CUT/PASTE the folder to this bucket and delete the bucket.
Upvotes: 10
Reputation: 31
Tried various alternatives to delete from Web interface to delete a folder with sub folders in it without luck. I had an installation of S3 browser and then tried from S3 Browser interface, worked.
Upvotes: 3
Reputation: 494
I had the same problem in the AWS web interface after AWS Command Line (CLI)-deleting a "recursive" folder in a bucket. Some objects randomly reappeared (not files, but in fact "folders") in the web interface. Even though i tried to delete these folders in the web interface, they were still there (The interface said the operation was successful...)
Solution that worked for me in the AWS web interface: Right clicked the folder -> CUT, and PASTE into another folder. Worked great, and then deleted the new folder. Gone!
Upvotes: 38
Reputation: 8231
I think I'm seeing similar behavior. My bucket has versioning turned on; even with an empty folder/directory within the bucket, attempting to "delete" the folder/directory within the bucket via the AWS web UI console does not result in it actually being removed. I presume the "deleted" versions of the files within that path still exist (but are not visible in the web console), therefore the bucket isn't truly empty, and isn't truly getting deleted. You may need to check via the CLI tools if existing deleted versions of files in that folder/directory exist (but are not visible in the web console) and delete the files permanently, then attempt to remove the folder/directory in your bucket.
Upvotes: 2
Reputation: 19563
S3 does not actually use folders. Instead the path separators in object paths are treated like folders. If you want to remove a folder, all the contents of the folder will have to get deleted.
If there is any delay in deleting all of the contents, the folder may continue to exist.
Upvotes: 7