0

I want to delete folders from aws s3 my-bucket which are older than 2023-05-01 and folder names which starts with "000". using AWS CLI

I can delete folders and files which starts with "000" using :

aws s3 rm s3://my-bucket --exclude "*" --include "000*" --recursive

now i want to add date condition into it. How can I achieve it?

I tried

aws s3 rm s3://my-bucket/ | awk '$1< "2023-10-28 11:30:15" {print $0}'

but it didnt work. Its saying he system can not find file specified

5
  • Does this answer your question? How list Amazon S3 bucket contents by modified date? Commented Sep 20, 2023 at 8:29
  • Unclear why you thought the 2nd command line was going to work. It's running aws s3 rm on the bucket and then piping the output of that command to awk. It doesn't, in any way, modify what the aws s3 rm command does. Commented Sep 20, 2023 at 12:59
  • @jarmod I tried ls but still it is not working Commented Sep 20, 2023 at 13:26
  • You're going to need to get a list of S3 objects older than the given date (see the earlier link) and then delete them one by one using aws s3 rm. Note: folders don't have a last modified date in S3 (because there typically are no actual folders, they're virtual). Commented Sep 20, 2023 at 15:38
  • @Paolo what we are going to do is : 1.Empty the bucket 2. add back the folder (TestAutomation) which we dont wanted to delete and then when adding this folders we will be adding tags to object inside it (like deletable = false). And will define new lifecycle policy for this bucket so that in future we dont have to delete s objects manually Commented Sep 21, 2023 at 18:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.