Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Deploy a Static Website using Oracle Cloud Infrastructure API Gateway
Introduction
Oracle Cloud Infrastructure (OCI) API Gateway is a serverless fully-managed service in OCI that can be used to protect API endpoints and web applications. It provides many security functionalities like rate limiting, authorization enforcement, dynamic routing, SSL enforcement, and so on. In this tutorial we discuss on how we can push a static website to OCI API Gateway to serve as website
Objectives
- Deploy a static website to OCI API Gateway to serve as website.
Prerequisites
-
Access to OCI API Gateway with appropriate permissions to configure the API gateway and deployment.
-
A static website ready to be running behind OCI API Gateway.
Task 1: Prepare your Static Website
Ensure you have your static website contents ready, this includes HTML, CSS, Javascript files and any other assets contained in your website.
Task 2: Run the Python Script to Create a json
File
Download the Python script from here: ap_gw.py. The script accepts two inputs a directory which contians all your static website files and the directory (with the file name) where the json
file will be stored. The outputted json
file can then be uploaded on the OCI API Gateway as a specification which will create seperate paths for each file and the respective paths can be refrenced within the files to reach the specific HTML, CSS, Javascript or any other file hosted behind the API gateway. The OCI API Gateway has a restriction that the max body size allowed is 4096 Bytes, so while executing the script if the body size in the body section while creating the json
exceeds 4096 bytes the script will throw an error and the execution stops. Here is an example of how the script can be run on Windows.
Note:
C:\Website
is the path where your website files are located andC:\Test\output.json
is the path where thejson
file will be stored.
Task 3: Configure OCI API Gateway and Upload the json
File as a API Specification on the OCI API Gateway
-
Log in to the OCI Console, go to Developer Services, API Management and API Gateway.
-
Under Gateways, go to your API gateway where you want to run this deployment. If you have not created an API gateway, click Create Gateway to create an API gateway.
-
In the Gateway Details page, select Deployments from the Resources list, and click Create Deployment.
-
In the Basic Details page, enter the following information and click Next. Additionally, you can also add authentication and other controls if required.
- Select Upload an existing deployment API.
- Name: Enter a deployment name.
- Path prefix: Enter a unique path. For example,
/
. - Specification: Upload the
json
file created in Task 2.
-
In the Review page, review the deployment and click Create.
Once that is done you can browse the home page of your website or the index.html (or any other path whichever is applicable for your website). Now, you can browse the homepage of your website or the index.html
(or any other applicable path for your site). Your website will now be running behind the OCI API Gateway, typically accessible using a URL like https://xxxxxxxxxxx.apigateway.us-ashburn-1.oci.customer-oci.com/index.html
.
Related Links
Acknowledgments
- Author - Aqib Javid Bhat (Senior Cloud Engineer)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Deploy a Static Website using Oracle Cloud Infrastructure API Gateway
G11484-01
July 2024