Serverless Computing on OCI
OCI Functions is Oracle’s serverless compute platform, based on the open-source Fn Project. Functions execute in response to events, scaling automatically from zero to thousands of concurrent executions. For Oracle database developers, Functions provide a way to run code in response to cloud events, file uploads, or HTTP requests without managing servers.
Common Use Cases
Process uploaded files: When a CSV is uploaded to Object Storage, a Function automatically parses it and loads data into Autonomous Database. Respond to database events: Use Database Events to trigger a Function when specific tables change. Send notifications: When a scheduled job detects an anomaly, a Function sends alerts through OCI Notifications, email, or Slack. API composition: A Function calls multiple REST APIs, aggregates results, and returns a unified response.
Writing a Function in Python
import io
import json
import oci
from fdk import response
def handler(ctx, data: io.BytesIO = None):
try:
body = json.loads(data.getvalue())
bucket = body.get("bucketName")
object_name = body.get("objectName")
# Connect to Autonomous Database
signer = oci.auth.signers.get_resource_principals_signer()
db_client = oci.database.DatabaseClient({}, signer=signer)
# Process the uploaded file
result = process_file(bucket, object_name)
return response.Response(
ctx, response_data=json.dumps({"status": "success", "rows": result}),
headers={"Content-Type": "application/json"}
)
except Exception as e:
return response.Response(
ctx, response_data=json.dumps({"error": str(e)}),
headers={"Content-Type": "application/json"}, status_code=500
)
OCI Events and Notifications
OCI Events automatically emit events when resources change: Object Storage file uploads, Autonomous Database scaling, Compute instance state changes. Create an Event Rule that matches the event pattern and routes it to a Function, Notifications topic, or Streaming service.
OCI Notifications is a pub/sub service that delivers messages to subscribers through email, SMS, PagerDuty, Slack webhooks, or Functions. Create a Topic, add subscriptions, and publish messages programmatically or through Event Rules.
Connecting Functions to Oracle Database
Functions can connect to Autonomous Database using the Oracle Instant Client included in the Function’s Docker image. Store the database wallet in OCI Vault and retrieve it at function startup. Use connection pooling within the function to minimize connection overhead across invocations. For simple queries, consider using ORDS REST endpoints from the function instead of a direct database connection.