# How to delete an object from an Object Storage bucket

This guide walks you through deleting an Object Storage bucket's object using the [Console](https://console.azion.com/object-storage), [Azion API](https://api.azion.com/), [Azion CLI](/en/documentation/products/azion-cli/overview/), and [Azion Runtime](/en/documentation/runtime/api-reference/storage/).

import Tabs from '~/components/tabs/Tabs'
import DocButton from '~/components/webkit/DocButton.vue';
import Code from '~/components/Code/Code.astro'

## Deleting an object from a bucket

<Tabs client:visible>
    <Fragment slot="tab.console">Console</Fragment>
    <Fragment slot="tab.cli">Azion CLI</Fragment>
    <Fragment slot="tab.runtime">Azion Runtime</Fragment>
    <Fragment slot="tab.api">API</Fragment>

<Fragment slot="panel.console">

Access the [Azion Console](https://console.azion.com/object-storage) and follow the steps below:

    1. In the side menu, click on **Object Storage**.
    2. On the Object Storage page, click on the bucket you want.
    3. In the object list, locate the object you want to delete.
    4. Click on the Context Menu (three dots icon) on the right side of the object and select **Delete**.
    5. In the popup, confirm the deletion when prompted.

    ![Delete object](/assets/docs/images/uploads/delete-bucket-object-console.png)

</Fragment>

<Fragment slot="panel.cli">

## Requirements 

- [Azion CLI installed](/en/documentation/products/azion-cli/overview/#installing-azion-cli). 
- [A personal token configured](/en/documentation/devtools/cli/globals/#token).

To delete an object: 

```bash 
azion delete edge-storage object --bucket-name bucketname  --object-key objectname
```

</Fragment>

<Fragment slot="panel.api">

To delete an object, run the following `DELETE` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/), `<bucket_name>` with the name of your bucket, `<object_key>` with an ID or name for the object:

<Code lang="bash" code={`
curl --location --request DELETE 'https://api.azion.com/v4/storage/buckets/<bucket_name>/objects/<object_key>' \
--header 'Accept: application/json' \
--header 'Authorization: Token [TOKEN VALUE]'
`} />

You should receive the following response:

```json
{
  "state": "executed",
  "data": {
    "object_key": "people-100.txt"
  }
}
```

</Fragment>

<Fragment slot="panel.runtime">

You can create a function to delete an object:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Functions**.
2. Click the **+ Function** button.
3. Name your function. Example: `delete_object`.
4. In the **Code** tab, add the following JavaScript code:

```js
import Storage from "azion:storage";

async function handleRequest(event) {
    const bucket = "mybucket";
    const storage = new Storage(bucket);
    const key = "test";
    try{
        await storage.delete(key);
    }catch(error){
        return new Response(error, {status:500});
    }
    return new Response("Ok");
}

addEventListener("fetch", (event) => {
    event.respondWith(handleRequest(event));
});
```


:::note 
Remember to replace "mybucket" with your bucket's name and "test" with the object key.
:::

5. Click the **Save** button.

:::note
See the [Object Storage API](/en/documentation/runtime/api-reference/storage/) reference for more details on functions available for other types of requests.
:::

Once you have the function ready, you need to create an applications that will proxy the deleting process for the bucket and instantiate the function.

<DocButton href="/en/documentation/products/build/applications/first-steps/" label="Go to Applications first steps" kind="secondary" target="_blank" size="medium" />
<DocButton href="/en/documentation/products/guides/build/instantiate-functions/" label="Go to how to instantiate an function" kind="secondary" target="_blank" size="medium" />

</Fragment>
</Tabs>