This guide walks you through setting a bucket as origin of an applications using the Azion API, Azion CLI, and Azion Runtime.

Go to Object Storage reference

There are separate instructions for API v3 using legacy Origin settings and API v4 using the new Connector product.


Create a bucket and upload files

This section describes how you can upload objects to a bucket and maintain project structure using the Azion API. In this scenario, you’ll create a static application using two files, distributed into folders as follows:

src/index.html
src/styles/style.css
  1. Create the following index.html file inside of a local src directory:
src/index.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>
  1. Now create the style.css file, which is referenced in the HTML, under the styles folder in the same directory:
src/styles/style.css
body {
background-color: black;
}
h1, p {
color: #F3652B;
}
  1. Run the following POST request in your terminal, replacing [TOKEN VALUE] with your personal token and writing the desired bucket name in name to create a read-only bucket:
Terminal window
curl --location 'https://api.azion.com/v4/storage/buckets' --header 'Accept: application/json;' --header 'Content-Type: application/json' --header 'Authorization: Token [TOKEN VALUE]' --data '{
"name": "app-origin",
"edge_access": "read_only"
}'
  1. You should receive the following response:
{
"state": "executed",
"data": {
"name": "app-origin",
"edge_access": "read_only"
}
}
  1. Run the following POST requests in your terminal for each file, replacing <bucket_name> with the name of the bucket you just created:

    • For the index.html file, run the following command using src/index.html as the object key, and adding the object path as data:
Terminal window
curl --location 'https://api.azion.com/v4/storage/buckets/<bucket_name>/objects/src/index.html' --header 'Accept: application/json;' --header 'Content-Type: text/html' --header 'Authorization: Token [TOKEN VALUE]' --data '@./src/index.html'
  • For the styles.css file, run the following command using src/styles/style.css as the object key, and adding the object path as data:
Terminal window
curl --location 'https://api.azion.com/v4/storage/buckets/<bucket_name>/objects/src/styles/style.css' --header 'Accept: application/json;' --header 'Content-Type: text/css' --header 'Authorization: Token [TOKEN VALUE]' --data '@./src/styles/style.css'
  1. You should receive the following responses for the files:
{
"state": "executed",
"data": {
"object_key": "src/index.html"
}
}
{
"state": "executed",
"data": {
"object_key": "src/styles/style.css"
}
}

Create an applications and set origin type to Object Storage

Now that your bucket is populated with files, you can create a new applications and a domain to set the bucket as the origin of the content and serve these objects.

To facilitate this process, use the Applications Proxy template:

  1. Access Azion Console.
  2. On the homepage, select the + Create option.
  3. Find the Applications Proxy card in the templates section and select it.
  4. Give your application an easy-to-remember name.
  5. In Origin Address, type httpbin.org.
    • This is a temporary origin that will later be replaced with an Object Storage origin.
  6. In Route to bypass, type / to specify the root path of the application.
  7. Wait for the deployment process to finish.
  8. Copy the domain of the application, in the format http://xxxxxxxxxx.map.azionedge.net/.

Now you need to configure a new Object Storage origin and determine that your application should retrieve content from the bucket and prefix you created. To do so:

  1. Access Azion Console > Applications.
  2. Click the proxy application you created in the previous steps.
  3. Navigate to the Origins tab.
  4. Click the + Origin button.
  5. Give your origin an easy-to-remember name.
  6. In Origin Type, select Object Storage.
  7. In Bucket Name, add the name of the bucket you created in the previous steps.
  8. In Prefix, add /src, which is the prefix you added to the object keys uploaded previously.
  9. Click the Save button.

To activate the origin in your applications:

  1. Navigate to the Rules Engine tab.
  2. Select the Default Rule.
  3. Under Behaviors, in the Set Origin behavior, replace the Default Origin with the origin you created for your bucket.
  4. Click the Save button.
  5. Wait some time for the changes to propagate to the edge.

Once the changes have been made, access http://xxxxxxxxxx.map.azionedge.net/index.html to see the HTML file you uploaded with the applied CSS style.