Function as a Service
Execute code on demand with automatic scaling and pay-per-execution billing.
Overview
Function as a Service (FaaS) eliminates infrastructure management. Write your function, configure it, and the platform handles scaling, routing, and availability. Ideal for microservices, APIs, event-based tasks, and background jobs.
Prerequisites
- Dashboard or API access
- Code packaged (ZIP or container) or linked repository
- (Optional) Registry access for container deployments
- (Optional) CI/CD credentials for automated pipelines
Supported Runtimes
| Language | Versions |
|---|---|
| C# | 6.0, 7.0 |
| Java | 11, 17, 21 |
| Node.js | 18, 19, 20 |
| Python | 3.8, 3.9, 3.10 |
| Go | 1.20, 1.21 |
Step 1: Create Function
- Navigate to Compute > Function as a Service
- Click Create Function
- Configure:
| Setting | Description |
|---|---|
| Function name | e.g., processImage |
| Runtime | Select from supported versions |
| Entry point | Handler method (language-specific) |
| Code | Upload ZIP or link repository |
| Region | Deployment location |
- Click Create
Deployment takes seconds. Function is active when status shows Ready.
Step 2: Configure Runtime
| Setting | Description |
|---|---|
| Memory | 128 MB, 256 MB, etc. |
| Timeout | Max execution duration (default 60s) |
| Environment Variables | Runtime config and secrets |
| Concurrency | Min/max instances (0 enables scale-to-zero) |
| Trigger | HTTP endpoint, event, or cron schedule |
Step 3: CI/CD with GitHub Actions
name: "Deploy Function as a Service"
on:
push:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup runtime (if needed)
uses: actions/setup-node@v5
with:
node-version: "18"
- name: Build/package
run: |
zip -r function.zip .
- name: Deploy function
run: |
curl -X POST https://api.platform.example.com/v1/faas/functions/deploy \
-H "Authorization: Bearer ${{ secrets.FAAS_API_KEY }}" \
-F "name=myfunction" \
-F "runtime=nodejs18" \
-F "file=@function.zip"
Step 4: Invoke Function
HTTP Trigger
curl -X POST https://faas.example.net/functions/myfunction \
-H "Authorization: Bearer <TOKEN>" \
-d '{"key":"value"}'
Check logs to verify output. Scheduled or event triggers execute automatically.
Step 5: Scaling and Optimization
- Scale-to-zero when no traffic, scale up on demand
- Monitor invocation count, duration, memory, error rate
- Optimize memory/time to minimize cost
- Set minimum instances to reduce cold-start latency
Features Summary
| Feature | Description |
|---|---|
| Multiple Runtimes | C#, Java, Node.js, Python, Go |
| Flexible Triggers | HTTP, events, cron schedules |
| Zero Infrastructure | No servers or clusters to manage |
| Auto-scaling | Scale up on demand, scale-to-zero |
| Secrets Handling | Secure runtime config injection |
| CI/CD Integration | Automated deployment pipelines |
| Pay-per-use | Charged only for execution time |
| Full Observability | Logging, metrics, monitoring |
Code Examples
Python
def handler(event, context):
return "hello world"
Node.js
module.exports = {
handler: function (event, context) {
return 'hello world!';
}
}
Go
package kubeless
func Handler(event map[string]interface{}, context map[string]string) (string, error) {
return "Hello world!", nil
}
Java
public class Module {
public String handler(Map event, Map context) {
return "hello world";
}
}
C#
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class module
{
public Task handler(Dictionary k8Event, Dictionary k8Context)
{
return Task.FromResult("hello world");
}
}
Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Stuck deploying | Invalid package or runtime | Check build logs, verify runtime |
| Invocation error | Bug or missing dependency | Test locally, review logs |
| High cold-start latency | No minimum instances | Set min instances > 0 |
| Unsupported version | Runtime not available | Choose supported version |
| CI/CD failed | Invalid credentials | Verify API key and URL |