amazon-web-servicesincludeaws-clirm

AWS CLI error with delete objects recursively using include, exclude


I have various sub-directories inside my s3 bucket which contain 2 files, namely:

  1. pavement_suitability_final_result.gpkg
  2. Intermediate_Part1_output.gpkg

I wish to delete only the files named as Intermediate_Part1_output.gpkg, leaving the pavement_suitability_final_result.gpkg intact.

I tried the below commands, with no success:

  1. aws s3 rm s3://aitl-data-bucket-backup/4_8_2_processed/ --recursive --exclude "pavement_suitability_final_result.gpkg" --include "Intermediate_Part1_output.gpkg" --dryrun This deletes both the files ignoring my exclude command.

  2. aws s3 rm s3://aitl-data-bucket-backup/4_8_2_processed/ --recursive --exclude "*" --include "Intermediate_Part1_output.gpkg" --dryrun This also deletes both the files ignoring my include command.

Tried various other combinations, but to no avail.


Solution

  • I suspect that it looks at the provided name as the full path of the object rather than just the 'filename' portion.

    Try something like:

    --exclude "*" --include "*/Intermediate_Part1_output.gpkg"
    

    This will look for that filename in subdirectories too.