# How to list objects in an Object Storage bucket

This guide walks you through listing the objects in an Object Storage bucket 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'

## Listing a bucket's objects

<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 to list objects from.
    3. On the bucket page, you will see the list of objects.

    ![List objects](/assets/docs/images/uploads/listar-objects-bucket-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 list the objects in an Object Storage bucket: 

```bash 
azion list edge-storage object --bucket-name bucketname 
```

</Fragment>

<Fragment slot="panel.api">

To list the objects in a bucket, run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/) and `<bucket_name>` with the name of your bucket:

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

You should receive the following response:

```json
{
  "continuation_token": null,
  "results": [
    {
      "key": "index.html",
      "last_modified": "2024-01-18T18:47:18.886000Z",
      "size": 217
    }
  ]
}
```

</Fragment>

<Fragment slot="panel.runtime">

You can create a function to list your objects in a bucket:

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

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

async function handleRequest(event) {
    try{
        const bucket = "mybucket";
        const storage = new Storage(bucket);
        const objectsList = await storage.list();
        for (const entry of objectsList.entries) {
            console.log(`key: ${entry.key} length: ${entry.content_length}`);
        }
        return new Response("Ok");
    }catch(error){
        return new Response(error, {status:500});
    }
}

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

:::note 
Remember to replace "mybucket" with your bucket's name.
:::

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 the function is ready, you need to create an applications that will proxy the listing 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 a function" kind="secondary" target="_blank" size="medium" />

</Fragment>
</Tabs>