How to delete images with suffix from folder in S3 bucketWhy do people use Heroku when AWS is present? What distinguishes Heroku from AWS?how to retrive objects in bucket with 'suffix'Delete folders in a bucket aws s3 which the names contain spaces?Boto3 to download all files from a S3 Bucketdelete files from a particular folder automatically in aws s3 bucketHow to setup lifecycle to delete folders under s3 bucket using boto3Process files from multiple folders in S3 bucketDelete files from folder in S3 bucketDelete files from folders on S3 bucketHow to check give directory or folder exist in given s3 bucket and if exist how to delete the folder from s3?

Crop image to path created in TikZ?

How can I plot a Farey diagram?

If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?

Is it wise to focus on putting odd beats on left when playing double bass drums?

Shall I use personal or official e-mail account when registering to external websites for work purpose?

Can I find out the caloric content of bread by dehydrating it?

Where else does the Shulchan Aruch quote an authority by name?

What to wear for invited talk in Canada

Is there a name of the flying bionic bird?

I see my dog run

Is Social Media Science Fiction?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

What does 'script /dev/null' do?

Does it makes sense to buy a new cycle to learn riding?

What are the advantages and disadvantages of running one shots compared to campaigns?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Is there a way to make member function NOT callable from constructor?

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

What is the meaning of "of trouble" in the following sentence?

Why is my log file so massive? 22gb. I am running log backups

Symmetry in quantum mechanics

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Domain expired, GoDaddy holds it and is asking more money

Why airport relocation isn't done gradually?



How to delete images with suffix from folder in S3 bucket


Why do people use Heroku when AWS is present? What distinguishes Heroku from AWS?how to retrive objects in bucket with 'suffix'Delete folders in a bucket aws s3 which the names contain spaces?Boto3 to download all files from a S3 Bucketdelete files from a particular folder automatically in aws s3 bucketHow to setup lifecycle to delete folders under s3 bucket using boto3Process files from multiple folders in S3 bucketDelete files from folder in S3 bucketDelete files from folders on S3 bucketHow to check give directory or folder exist in given s3 bucket and if exist how to delete the folder from s3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have store multiple sizes of the image on s3.
e.g. image100_100,image200_200,image300_150;



I want to delete the specific size of images like images with suffix 200_200 from the folder. there are a lot of images in this folder so how to delete these images?










share|improve this question
























  • Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

    – vahdet
    Mar 8 at 7:27


















0















I have store multiple sizes of the image on s3.
e.g. image100_100,image200_200,image300_150;



I want to delete the specific size of images like images with suffix 200_200 from the folder. there are a lot of images in this folder so how to delete these images?










share|improve this question
























  • Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

    – vahdet
    Mar 8 at 7:27














0












0








0








I have store multiple sizes of the image on s3.
e.g. image100_100,image200_200,image300_150;



I want to delete the specific size of images like images with suffix 200_200 from the folder. there are a lot of images in this folder so how to delete these images?










share|improve this question
















I have store multiple sizes of the image on s3.
e.g. image100_100,image200_200,image300_150;



I want to delete the specific size of images like images with suffix 200_200 from the folder. there are a lot of images in this folder so how to delete these images?







amazon-web-services amazon-s3 boto3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 5:52









John Rotenstein

78.3k789139




78.3k789139










asked Mar 8 at 7:25









SK2609SK2609

11




11












  • Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

    – vahdet
    Mar 8 at 7:27


















  • Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

    – vahdet
    Mar 8 at 7:27

















Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

– vahdet
Mar 8 at 7:27






Ok, through what? A lambda function? If so, in what language (Python, Java, Go etc.)?

– vahdet
Mar 8 at 7:27













2 Answers
2






active

oldest

votes


















0














The easiest method would be to write a Python script, similar to:



import boto3

BUCKET = 'my-bucket'
PREFIX = '' # eg 'images/'

s3_client = boto3.client('s3', region_name='ap-southeast-2')

# Get a list of objects
list_response = s3_client.list_objects_v2(Bucket = BUCKET, Prefix = PREFIX)

while True:
# Find desired objects to delete
objects = ['Key':object['Key'] for object in list_response['Contents'] if object['Key'].endswith('200_200')]
print ('Deleting:', objects)

# Delete objects
if len(objects) > 0:
delete_response = s3_client.delete_objects(
Bucket=BUCKET,
Delete='Objects': objects
)

# Next page
if list_response['IsTruncated']:
list_response = s3_client.list_objects_v2(
Bucket = BUCKET,
Prefix = PREFIX,
ContinuationToken=list_reponse['NextContinuationToken'])
else:
break





share|improve this answer






























    0














    Use AWS command-line interface (AWS CLI):



    aws s3 rm s3://Path/To/Dir/ --recursive --exclude "*" --include "*200_200"


    We first exclude everything, then include what we need to delete. This is a workaround to mimic the behavior of rm -r "*200_200" command in Linux.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058542%2fhow-to-delete-images-with-suffix-from-folder-in-s3-bucket%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The easiest method would be to write a Python script, similar to:



      import boto3

      BUCKET = 'my-bucket'
      PREFIX = '' # eg 'images/'

      s3_client = boto3.client('s3', region_name='ap-southeast-2')

      # Get a list of objects
      list_response = s3_client.list_objects_v2(Bucket = BUCKET, Prefix = PREFIX)

      while True:
      # Find desired objects to delete
      objects = ['Key':object['Key'] for object in list_response['Contents'] if object['Key'].endswith('200_200')]
      print ('Deleting:', objects)

      # Delete objects
      if len(objects) > 0:
      delete_response = s3_client.delete_objects(
      Bucket=BUCKET,
      Delete='Objects': objects
      )

      # Next page
      if list_response['IsTruncated']:
      list_response = s3_client.list_objects_v2(
      Bucket = BUCKET,
      Prefix = PREFIX,
      ContinuationToken=list_reponse['NextContinuationToken'])
      else:
      break





      share|improve this answer



























        0














        The easiest method would be to write a Python script, similar to:



        import boto3

        BUCKET = 'my-bucket'
        PREFIX = '' # eg 'images/'

        s3_client = boto3.client('s3', region_name='ap-southeast-2')

        # Get a list of objects
        list_response = s3_client.list_objects_v2(Bucket = BUCKET, Prefix = PREFIX)

        while True:
        # Find desired objects to delete
        objects = ['Key':object['Key'] for object in list_response['Contents'] if object['Key'].endswith('200_200')]
        print ('Deleting:', objects)

        # Delete objects
        if len(objects) > 0:
        delete_response = s3_client.delete_objects(
        Bucket=BUCKET,
        Delete='Objects': objects
        )

        # Next page
        if list_response['IsTruncated']:
        list_response = s3_client.list_objects_v2(
        Bucket = BUCKET,
        Prefix = PREFIX,
        ContinuationToken=list_reponse['NextContinuationToken'])
        else:
        break





        share|improve this answer

























          0












          0








          0







          The easiest method would be to write a Python script, similar to:



          import boto3

          BUCKET = 'my-bucket'
          PREFIX = '' # eg 'images/'

          s3_client = boto3.client('s3', region_name='ap-southeast-2')

          # Get a list of objects
          list_response = s3_client.list_objects_v2(Bucket = BUCKET, Prefix = PREFIX)

          while True:
          # Find desired objects to delete
          objects = ['Key':object['Key'] for object in list_response['Contents'] if object['Key'].endswith('200_200')]
          print ('Deleting:', objects)

          # Delete objects
          if len(objects) > 0:
          delete_response = s3_client.delete_objects(
          Bucket=BUCKET,
          Delete='Objects': objects
          )

          # Next page
          if list_response['IsTruncated']:
          list_response = s3_client.list_objects_v2(
          Bucket = BUCKET,
          Prefix = PREFIX,
          ContinuationToken=list_reponse['NextContinuationToken'])
          else:
          break





          share|improve this answer













          The easiest method would be to write a Python script, similar to:



          import boto3

          BUCKET = 'my-bucket'
          PREFIX = '' # eg 'images/'

          s3_client = boto3.client('s3', region_name='ap-southeast-2')

          # Get a list of objects
          list_response = s3_client.list_objects_v2(Bucket = BUCKET, Prefix = PREFIX)

          while True:
          # Find desired objects to delete
          objects = ['Key':object['Key'] for object in list_response['Contents'] if object['Key'].endswith('200_200')]
          print ('Deleting:', objects)

          # Delete objects
          if len(objects) > 0:
          delete_response = s3_client.delete_objects(
          Bucket=BUCKET,
          Delete='Objects': objects
          )

          # Next page
          if list_response['IsTruncated']:
          list_response = s3_client.list_objects_v2(
          Bucket = BUCKET,
          Prefix = PREFIX,
          ContinuationToken=list_reponse['NextContinuationToken'])
          else:
          break






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 5:52









          John RotensteinJohn Rotenstein

          78.3k789139




          78.3k789139























              0














              Use AWS command-line interface (AWS CLI):



              aws s3 rm s3://Path/To/Dir/ --recursive --exclude "*" --include "*200_200"


              We first exclude everything, then include what we need to delete. This is a workaround to mimic the behavior of rm -r "*200_200" command in Linux.






              share|improve this answer



























                0














                Use AWS command-line interface (AWS CLI):



                aws s3 rm s3://Path/To/Dir/ --recursive --exclude "*" --include "*200_200"


                We first exclude everything, then include what we need to delete. This is a workaround to mimic the behavior of rm -r "*200_200" command in Linux.






                share|improve this answer

























                  0












                  0








                  0







                  Use AWS command-line interface (AWS CLI):



                  aws s3 rm s3://Path/To/Dir/ --recursive --exclude "*" --include "*200_200"


                  We first exclude everything, then include what we need to delete. This is a workaround to mimic the behavior of rm -r "*200_200" command in Linux.






                  share|improve this answer













                  Use AWS command-line interface (AWS CLI):



                  aws s3 rm s3://Path/To/Dir/ --recursive --exclude "*" --include "*200_200"


                  We first exclude everything, then include what we need to delete. This is a workaround to mimic the behavior of rm -r "*200_200" command in Linux.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 9 at 6:15









                  LoMaPhLoMaPh

                  3311714




                  3311714



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058542%2fhow-to-delete-images-with-suffix-from-folder-in-s3-bucket%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      1928 у кіно

                      Захаров Федір Захарович

                      Ель Греко