Use an Object Storage Bucket as Origin
Learn how to use a bucket as the origin of a static applications using Object Storage and make the bucket content public.
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 referenceThere 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:
- Create the following
index.htmlfile inside of a localsrcdirectory:
- Now create the
style.cssfile, which is referenced in the HTML, under thestylesfolder in the same directory:
- Run the following
POSTrequest in your terminal, replacing[TOKEN VALUE]with your personal token and writing the desired bucket name innameto create a read-only bucket:
- You should receive the following response:
-
Run the following
POSTrequests in your terminal for each file, replacing<bucket_name>with the name of the bucket you just created:- For the
index.htmlfile, run the following command usingsrc/index.htmlas the object key, and adding the object path as data:
- For the
- For the
styles.cssfile, run the following command usingsrc/styles/style.cssas the object key, and adding the object path as data:
- You should receive the following responses for the files:
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:
- Access Azion Console.
- If you don’t have an account yet, create a new one by visiting the sign-up page.
- On the homepage, select the + Create option.
- Find the Applications Proxy card in the templates section and select it.
- Give your application an easy-to-remember name.
- In Route to bypass, type
/to specify the root path of the application. - Wait for the deployment process to finish.
- Copy the domain of the application, in the format
http://xxxxxxxxxx.map.azionedge.net/.
Now you need to configure a new Connector to link your application to your Object Storage bucket. To do so:
- Access Azion Console > Connectors.
- Click the + Connector button.
- In the General section, give your connector a unique and descriptive name (e.g.,
My Object Storage Connector). - In the Connector Type section, select Object Storage.
- In the Connection Options section:
- For Bucket, select the name of the bucket you created in the previous steps. The bucket selector lists your existing buckets and provides a search field.
- For Prefix, enter
/src(or the prefix you used when uploading your objects).
- Set the Status to Active.
- Click the Save button.
To activate the Connector in your applications:
- Access the Rules Engine tab.
- Edit the default rule or add a new request rule.
- In the Criteria section, to apply the Connector for your whole application, set the criteria to
If ${uri} starts with /. - In the Behavior section, select the Set Connector behavior.
- Select the Connector you want to apply.
- Click the Save button.
- 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.
To facilitate this process, use the Applications Proxy template:
- Access Azion Console.
- If you don’t have an account yet, create a new one by visiting the sign-up page.
- On the homepage, select the + Create option.
- Find the Applications Proxy card in the templates section and select it.
- Give your application an easy-to-remember name.
- In Origin Address, type
httpbin.org.- This is a temporary origin that will later be replaced with an Object Storage origin.
- In Route to bypass, type
/to specify the root path of the application. - Wait for the deployment process to finish.
- 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:
- Access Azion Console > Applications.
- Click the proxy application you created in the previous steps.
- Navigate to the Origins tab.
- Click the + Origin button.
- Give your origin an easy-to-remember name.
- In Origin Type, select Object Storage.
- In Bucket Name, add the name of the bucket you created in the previous steps.
- In Prefix, add
/src, which is the prefix you added to the object keys uploaded previously. - Click the Save button.
To activate the origin in your applications:
- Navigate to the Rules Engine tab.
- Select the Default Rule.
- Under Behaviors, in the Set Origin behavior, replace the Default Origin with the origin you created for your bucket.
- Click the Save button.
- 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.
- Run the following
POSTrequest in your terminal, replacing[TOKEN VALUE]with your personal token:
- You should receive a response similar to:
-
Copy the value from the
edge_application_idfield and paste it in a text editing app to save it for later requests. -
Run the following
POSTrequest in your terminal to create an Connector, replacing[TOKEN VALUE]with your personal token
-
Copy the value from the
<connector_id>field and paste it in a text editing app to save it for later requests. -
You should receive a response similar to:
- Run the following
POSTrequest in your terminal, replacing[TOKEN VALUE]with your personal token
- You should receive a response similar to:
-
Copy the URL in the
workload_domainvalue and paste it in a text editing app to access later. -
Run the following
POSTrequest to bind the Workload to your Applications, replacing[TOKEN VALUE]with your personal token,<edge_application_id>with the ID of the applications and<workload_id>with the id of the Workload.
- Run the following
POSTrequest in your terminal to create a Rules Engine rule, replacing<edge_application_id>variable with the Applications ID and<connector_id>with the Connector ID you copied previously:
- You should receive a response similar to:
- Wait some time for the changes to propagate.
Once the changes have been made, access the domain you created, in the format http://xxxxxxxxxx.map.azionedge.net/index.html, to see the HTML file you uploaded with the applied CSS style.
- Run the following
POSTrequest in your terminal, replacing[TOKEN VALUE]with your personal token:
- You should receive a response similar to:
- Copy the value from the
edge_application_idfield and paste it in a text editing app to save it for later requests. - Run the following
POSTrequest in your terminal, replacing[TOKEN VALUE]with your personal token and<edge_application_id>with the ID of the applications you created:
- You should receive a response similar to:
- Copy the URL in the
domain_namevalue and paste it in a text editing app to access later. - Run the following
POSTrequest to create an object storage origin for the application, replacing[TOKEN VALUE]with your personal token,<edge_application_id>with the ID of the applications, and the value ofbucketwith the name of the bucket you created:
- You should receive a response similar to:
- Copy the value from the
origin_idfield and paste it in a text editing app to save it for later requests. - Run the following
GETrequest in your terminal to retrieve the ID of the default rule of your applications’s Rules Engine, replacing<edge_application_id>variable with the applications ID you copied previously:
- You should receive a response similar to:
- Copy the value from the
rule_idfield and paste it in a text editing app to save it for later requests. - Run the following
PATCHrequest to modify the default rule, replacing<rule_id>with the ID of the rule you retrieved in the previous step, leaving theset_cache_policyobject the same as received in the response:
- Wait some time for the changes to propagate.
Once the changes have been made, access the domain you created, in the format http://xxxxxxxxxx.map.azionedge.net/index.html, to see the HTML file you uploaded with the applied CSS style.