Use a bucket as an application origin
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.
You can serve the objects of an Object Storage bucket through an application. 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.
Prerequisites
Console
- A bucket whose
workloads_accessisread_onlyorread_write. Arestrictedbucket cannot back an application. To create a bucket, refer to 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.
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:
In a local src directory, create index.html. The page links its stylesheet by a relative path:
In a styles directory inside src, create style.css, the file the page links to:
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.
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:
Access Azion Console > Applications > your application.
In the Origins tab, select + Origin and name it.
In Origin Type, select Object Storage.
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.
Select Save.
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.
For every field of the origin, refer to 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>:
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.