Note:

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

Prerequisites

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.

Image 6

Note: C:\Website is the path where your website files are located and C:\Test\output.json is the path where the json file will be stored.

Task 3: Configure OCI API Gateway and Upload the json File as a API Specification on the OCI API Gateway

  1. Log in to the OCI Console, go to Developer Services, API Management and API Gateway.

  2. 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.

    Image 1

  3. In the Gateway Details page, select Deployments from the Resources list, and click Create Deployment.

    Image 2

  4. 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.

    Image 3

  5. 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.

Image 5

Acknowledgments

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.