I'm trying to delete an empty folder structure using the cli and noting seems to be working. The root folder is / 7000/ and I'm positive it's because of the " "
My rm commands are working on other folders without special characters and the cli isn't returning an error. How would I build this script to recognize this folder and get rid of it?
Test Scripts
(+ is ' ' in hex)
>aws s3 ls
2022-07-13 10:29:36 0 +7000/
>
>
//Attempts
> aws s3 rm s3://namespace/ --exclude "*" --include "+7000/"
> aws s3 rm s3://namespace/ --exclude "*" --include "*7000/"
> aws s3 rm s3://namespace/ --exclude "*" --include "[ ]7000/"
> aws s3 rm s3://namespace/ --exclude "*" --include "' 7000'/"
> aws s3 rm s3://namespace/"\ 7000/"
> aws s3 rm s3://namespace/+7000/
delete: s3://namespace/+7000/
Most attempts return a successful deletion but the folder is still there.
Output from aws s3api list-objects --bucket namespace
{
"Key": " 7000/",
"LastModified": "2022-07-13T14:29:36.884Z",
"ETag": "\"100\"",
"Size": 0,
"StorageClass": "STANDARD",
"Owner": {
"DisplayName": "vmsstg",
"ID": "1-2-3-4"
}
}
CodePudding user response:
If aws s3 rm
isn't working, you can try the 'lower-level' API call:
aws s3api delete-object --bucket namespace --key +7000/
Given that you said that +
is plus, and based on your comment, you can use:
aws s3api delete-object --bucket namespace --key " 7000/"
I guess the plus sign got translated into 'URL Encode' syntax somewhere along the way.
Another approach is to use an AWS SDK (eg boto3 for Python) to retrieve the Key and then delete the object by passing back the exact value. This would avoid any encoding in the process.