Questo contenuto non è disponibile nella lingua selezionata.

Chapter 9. Deleting files from your bucket


To delete files from your bucket from your workbench, use the delete_file() method.

Prerequisites

  • You have cloned the odh-doc-examples repository to your workbench.
  • You have opened the s3client_examples.ipynb file in your workbench.
  • You have installed Boto3 and configured an S3 client.
  • You know the key of the file you want to delete and the bucket that the file is located in.

Procedure

  1. In the Jupyter notebook, locate the following instructions to delete files from a bucket:

    #Delete files from bucket
    s3_client.delete_object(Bucket='<bucket_name>', Key='<object_key>')
  2. Replace <bucket_name> with the name of your bucket and <key> with the key of the file you want to delete, as shown in the example. Run the code cell.

    #Delete object from bucket
    s3_client.delete_object(Bucket='aqs971-image-registry', Key='/tmp/series43-image12-086.csv')

    The output displays a HTTP response status code of 204, which indicates that the request was successful.

Verification

  • Locate the following instructions to list files in a bucket:

    #Delete Object Verification
    bucket_name = '<bucket_name>'
    for key in s3_client.list_objects_v2(Bucket=bucket_name)['Contents']:
    print(key['Key'])
  • Replace <bucket_name> with the name of your bucket, as shown in the example and run the code cell.

    #Delete Object Verification
    bucket_name = 'aqs971-image-registry'
    for key in s3_client.list_objects_v2(Bucket=bucket_name)['Contents']:
    print(key['Key'])

    The deleted file does not appear in the output.

Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat
Torna in cima