---
name: azion-use-a-bucket-as-an-application-origin
description: >-
  Serve the objects of an Object Storage bucket through an application, with an origin of the Object Storage type and a rule that points the application at it.
---

# Use a bucket as an application origin

> Platform versions: this page applies to API v3.x only, not to API v6.x and API v4.x.
> Equivalent page for API v4.x: [Use a bucket as an application origin](/en/documentation/guides/application-development/data/use-bucket-as-origin.md)
> Release stage: Deprecated.

You can serve the objects of an [Object Storage](/en/documentation/platform/object-storage/) bucket through an [application](/en/documentation/platform/applications/v3/). The bucket is an origin of the application, of the **Object Storage** type, and a rule points the application at it. A request to a hostname of the application then returns the object stored under the matching key. For every field of an origin, refer to [Origins](/en/documentation/platform/connectors/origins/).

---

## Prerequisites

### Console

- A bucket whose `workloads_access` is `read_only` or `read_write`. A `restricted` bucket cannot back an application. To create a bucket, refer to [Object Storage quickstart](/en/documentation/platform/object-storage/quickstart/).
- An application, and a hostname that reaches it.
- `curl`, or another HTTP client.
- Access to Azion Console. To sign in, refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

### API

- A bucket whose `workloads_access` is `read_only` or `read_write`. A `restricted` bucket cannot back an application. To create a bucket, refer to [Object Storage quickstart](/en/documentation/platform/object-storage/quickstart/).
- An application, and a hostname that reaches it.
- A personal token, sent in the `Authorization` header as `Token [TOKEN VALUE]`. To create a token, refer to [Manage a personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- `curl`, or another HTTP client.
- The ID of the application.

---

## Upload the objects to serve

The origin serves what the bucket already holds, so the objects go in first. The example on this page serves a page of two objects, both stored under the `src` prefix of a bucket named `app-origin`:

```text
src/index.html
src/styles/style.css
```

In a local `src` directory, create `index.html`. The page links its stylesheet by a relative path:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="styles/style.css">
</head>
<body>
    <h1>Hello world!</h1>
    <p>I am an object from a bucket.</p>
</body>
</html>
```

In a `styles` directory inside `src`, create `style.css`, the file the page links to:

```css
body {
  background-color: black;
}

h1,
p {
  color: white;
}
```

Upload both files to the bucket, under the keys `src/index.html` and `src/styles/style.css`, from Azion Console or the Azion CLI. For more information, refer to [Object Storage quickstart](/en/documentation/platform/object-storage/quickstart/).

The `src/` segment of each key is part of the key, not a folder, and the platform creates it with the object.

---

## Serve the bucket from the application

The origin names the bucket and the prefix of the object keys to serve. With the prefix `/src`, the object stored under `src/index.html` answers at `/index.html`, and `src/styles/style.css` answers at `/styles/style.css`.

### Console

To serve the objects from the application in Azion Console:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **Add the origin**

   In the **Origins** tab, select **+ Origin** and name it.

3. **Choose the Object Storage type**

   In **Origin Type**, select **Object Storage**.

4. **Name the bucket and the prefix**

   In **Bucket Name**, enter the name of your bucket. In **Prefix**, enter the prefix of the object keys you want to serve, such as `/src`. Leave it empty to serve the whole bucket.

5. **Save the origin**

   Select **Save**.

6. **Point the application at the origin**

   In the **Rules Engine** tab, select **Default Rule**. Under **Behaviors**, in the **Set Origin** behavior, replace **Default Origin** with the origin you created, and select **Save**.

### API

To serve the bucket with the API, create the origin on the application and then point its default rule at it. Both requests carry the header `Accept: application/json; version=3`.

Create the origin:

```bash
curl --request POST \
  --url https://api.azionapi.net/edge_applications/<application-id>/origins \
  --header 'Accept: application/json; version=3' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]' \
  --data '{
  "name": "object storage origin",
  "origin_type": "object_storage",
  "bucket": "app-origin",
  "prefix": "/src"
}'
```

The response carries the `origin_id` of the new origin:

```json
{
  "results": {
    "origin_id": 123456,
    "origin_key": "bdcd7003-ba53-4ed8-8ca0-05b1357cdafd",
    "name": "object storage origin",
    "origin_type": "object_storage",
    "bucket": "app-origin",
    "prefix": "/src"
  }
}
```

Then read the rules of the request phase to find the ID of the default rule:

```bash
curl --request GET \
  --url https://api.azionapi.net/edge_applications/<application-id>/rules_engine/request/rules \
  --header 'Accept: application/json; version=3' \
  --header 'Authorization: Token [TOKEN VALUE]'
```

The default rule carries `"phase": "default"` and its current behaviors:

```json
{
  "results": [
    {
      "id": 987654,
      "name": "Default Rule",
      "phase": "default",
      "behaviors": [
        { "name": "set_origin", "target": "<origin-id>" },
        { "name": "set_cache_policy", "target": "<cache-setting-id>" }
      ]
    }
  ]
}
```

Finally, send a `PATCH` to that rule with the `set_origin` behavior. Keep the `set_cache_policy` behavior as the response returned it, or the rule loses its cache setting:

```bash
curl --request PATCH \
  --url https://api.azionapi.net/edge_applications/<application-id>/rules_engine/request/rules/<rule-id> \
  --header 'Accept: application/json; version=3' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]' \
  --data '{
  "behaviors": [
    { "name": "set_origin", "target": "<origin-id>" },
    { "name": "set_cache_policy", "target": "<cache-setting-id>" }
  ]
}'
```

| Key           | What it carries                                                                                     |
| ------------- | --------------------------------------------------------------------------------------------------- |
| `origin_type` | `object_storage` for a bucket origin                                                                |
| `bucket`      | The name of the bucket                                                                              |
| `prefix`      | The prefix of the object keys to serve. `/` serves the whole bucket                                 |
| `set_origin`  | The behavior that sets the origin of the requests the rule matches. Its `target` is the `origin_id` |

For every field of the origin, refer to [Origins](/en/documentation/platform/connectors/origins/).

---

## Confirm that the application serves the bucket

The rule takes some time to propagate. Until then, the application does not answer with the objects.

To confirm the delivery path, request the page through a hostname of your application, with that hostname in place of `<your-domain>`:

```bash
curl https://<your-domain>/index.html
```

The response body is the object stored under `src/index.html`, which the `/src` prefix serves at `/index.html`. It carries the heading `Hello world!` and the paragraph `I am an object from a bucket.`

Go to the same address in a browser. The browser renders the page with the stylesheet applied, which it loads from `/styles/style.css` under the same prefix.

If the hostname does not return the object yet, the rule has not propagated. Send the request again, and look for another cause only after that. For more information, refer to [Troubleshoot Applications](/en/documentation/platform/applications/troubleshooting/).

---

## Next steps

- [Cache settings](/en/documentation/platform/applications/cache/cache-settings.md): Set how long the objects the application serves stay cached.
- [Origins](/en/documentation/platform/connectors/origins.md#object-storage): Every field of an origin of the Object Storage type.
- [How Object Storage works](/en/documentation/platform/object-storage/how-it-works.md): What the access level changes, and the path a request takes to an object.
- [Buckets and objects](/en/documentation/platform/object-storage/buckets-and-objects.md): Bucket names, access levels, object keys, and prefixes.
