Folder won't delete on Amazon S3

馋奶兔 提交于 2019-12-21 03:37:40

问题


I'm trying to delete a folder created as a result of a MapReduce job. Other files in the bucket delete just fine, but this folder won't delete. When I try to delete it from the console, the progress bar next to its status just stays at 0. Have made multiple attempts, including with logout/login in between.


回答1:


First and foremost, Amazon S3 doesn't actually have a native concept of folders/directories, rather is a flat storage architecture comprised of buckets and objects/keys only - the directory style presentation seen in most tools for S3 (including the AWS Management Console itself) is based solely on convention, i.e. simulating a hierarchy for objects with identical prefixes - see my answer to How to specify an object expiration prefix that doesn't match the directory? for more details on this architecture, including quotes/references from the AWS documentation.

Accordingly, your problem might stem from a tool using a different convention for simulating this hierarchy, see for example the following answers in the AWS forums:

  • Ivan Moiseev's answer to the related question Cannot delete file from bucket, where he suggests to use another tool to inspect whether you might have such a problem and remedy it accordingly.

  • The AWS team response to What are these _$folder$ objects? - This is a convention used by a number of tools including Hadoop to make directories in S3. They're primarily needed to designate empty directories. One might have preferred a more aesthetic scheme, but well that is the way that these tools do it.

Good luck!




回答2:


I had the same issue and used AWS CLI to fix it:

aws s3 rm s3://<your-bucket>/<your-folder-to-delete>/ --recursive ;

(this assumes you have run aws configure and aws s3 ls s3://<your-bucket>/ already works)




回答3:


I was getting the following error when I tried to delete a bucket which was a directory that held log files from Cloudfront.

An unexpected error has occurred. Please try again later.

After I disabled logging in Cloudfront I was able to delete the folder successfully.

My guess is that it was a system folder used by Cloudfront that did not allow deletion by the owner.

In your case, you may want to check if MapReduce is holding on to the folder in question.




回答4:


I was facing the same problem. Tried many login, logout attempts and refresh but problem persist. Searched stackoverflow and found suggestions to cut and paste folder in different folder then delete but didn't worked. Another thing you should look is for versioning that might effect your bucket may be suspending the versioning allow you to delete the folder.

My solution was to delete it with code. I have used boto package in python for file handling over s3 and the deletion worked when I tried to delete that folder from my python code.

import boto
from boto.s3.key import Key
keyId = "your_aws_access_key"
sKeyId = "your_aws_secret_key"
fileKey="dummy/foldertodelete/" #Name of the file to be deleted
bucketName="mybucket001" #Name of the bucket, where the file resides
conn = boto.connect_s3(keyId,sKeyId) #Connect to S3
bucket = conn.get_bucket(bucketName) #Get the bucket object
k = Key(bucket,fileKey) #Get the key of the given object
k.delete() #Delete

S3 doesn't keep directory it just have a flat file structure so everything is managed with key. For you its a folder but for S3 it just an key.

If you want to delete a folder named -> dummy then key would be

fileKey = "/dummy/"



回答5:


Firstly, read the content of directory from getBucket method, then you got a array list of all files, then delete the file from deleteObject method.

 if (($contents = $this->S3->getBucket(AS_S3_BUCKET, "file_path")) !== false) 
 {
     foreach ($contents as $file) 
     {
     $result = $this->S3->deleteObject(AS_S3_BUCKET,$file['name']);
     }
 }

$this->S3 is S3 class object, and AS_S3_BUCKET is bucket name.



来源:https://stackoverflow.com/questions/9834409/folder-wont-delete-on-amazon-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!