Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 cli includes not working

Alright I'm very confused by aws cli

I have an S3 bucket:

s3://my-bucket
  directory/
    file1
    file2
  backup-logs-1234
  backup-logs-5678

I've verified that the files are in the s3 bucket, and I can see them with aws s3 ls s3://my-bucket

I'm trying to delete all the backup logs in the folder (8000 of them). I've tried every combination of includes/excludes I can think of

1) For some reason aws s3 rm "s3://my-bucket/" --include "*backup-logs*" --dryrun tries to delete s3://my-bucket/directory/

2) aws s3 rm "s3://my-bucket/" --exclude "*" --include "*backup-logs*" --dryrun doesn't see any files to delete

3) I've also tried different substrings of "backup" (eg. b, ba, back)

4) I've also tried adding recursive (even though I don't want it to be) and it finds all the files in directory/ that match the pattern, but none of the top level ones

I'm sure I'm doing something stupid. Thanks in advance for the help

like image 899
toppsdown Avatar asked Apr 12 '17 13:04

toppsdown


People also ask

How do I access Amazon S3 using aws cli?

The AWS CLI provides two tiers of commands for accessing Amazon S3: The s3 tier consists of high-level commands that simplify performing common tasks, such as creating, manipulating, and deleting objects and buckets. The s3api tier behaves identically to other AWS services by exposing direct access to all Amazon S3 API operations.

What is the difference between S3 and s3api?

The s3 tier consists of high-level commands that simplify performing common tasks, such as creating, manipulating, and deleting objects and buckets. The s3api tier behaves identically to other AWS services by exposing direct access to all Amazon S3 API operations.

Why can't I include/exclude S3 bucket names?

There was a bug in earlier versions that required the bucket name to be included for include/exclude filters for s3 locations, which is inconsistent with how local file include/exclude works. This has now been fixed and you're example should work on the latest version.

How to include/exclude filters in AWS S3?

In the command aws s3 sync /tmp/foo s3://bucket/ the source directory is /tmp/foo. Any include/exclude filters will be evaluated with the source directory prepended. Below are several examples to demonstrate this.


1 Answers

aws s3 rm s3://my-bucket/ --recursive --exclude "*" --include "*backup-logs*" should work.

When you want to delete multiple objects within your bucket

--recursive (boolean) Command is performed on all files or objects under the specified directory or prefix.

You can read on http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters about include/exclude use

like image 125
Frederic Henri Avatar answered Oct 20 '22 20:10

Frederic Henri