Function Lifecycle Management
ContainerPub provides comprehensive lifecycle management for serverless functions, from initialization through deployment, versioning, and eventual deletion.
Overview
The function lifecycle consists of several stages:
- Initialization - Create function record and get UUID
- Deployment - Upload code and build container
- Active - Function is running and accepting invocations
- Versioning - Track deployment history
- Rollback - Restore previous versions
- Deletion - Scheduled cleanup with grace period
Function Initialization
Before deploying a function, you must initialize it to receive a UUID.
POST /api/functions/init
Purpose: Creates a function record in the database with status init and generates a unique UUID.
Request:
{
"name": "my_function",
"skip_signing": false // Optional, default: false
}
Response (New Function):
{
"message": "Function initialized successfully",
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "my_function",
"status": "init",
"skip_signing": false,
"created_at": "2025-02-21T00:00:00Z"
}
Response (Existing Function):
{
"message": "Function already exists",
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "my_function",
"status": "active",
"skip_signing": false,
"deployment_version": 3,
"created_at": "2025-01-15T00:00:00Z",
"already_exists": true
}
Key Points:
- Function name must be unique per user
- Returns existing function if name already exists
- UUID is used for all subsequent operations
- skip_signing controls whether API key signatures are required
Deployment
After initialization, deploy your function code.
POST /api/functions/deploy
Request:
- function_id - UUID from init endpoint
- archive - Function code archive (tar.gz)
- env - Environment variables (JSON, optional)
Status Transitions:
init → building → activeFor redeployments:
active → building → active (new version)Versioning & Deployment History
Every deployment creates a new version. View complete deployment history with pagination.
GET /api/functions/:id/deployments
Query Parameters:
- page - Page number (default: 1)
- per_page - Results per page (default: 20, max: 100)
Response:
{
"function_uuid": "550e8400-e29b-41d4-a716-446655440000",
"function_name": "my-function",
"function_status": "active",
"page": 1,
"per_page": 20,
"count": 5,
"total_pages": 1,
"has_next": false,
"deployments": [
{
"uuid": "deployment-uuid-3",
"version": 3,
"image_tag": "registry/my-function:v3",
"s3_key": "functions/550e8400/v3.tar.gz",
"status": "active",
"is_active": true,
"created_at": "2025-02-21T10:00:00Z",
"deployed_at": "2025-02-21T10:01:30Z"
},
{
"uuid": "deployment-uuid-2",
"version": 2,
"image_tag": "registry/my-function:v2",
"s3_key": "functions/550e8400/v2.tar.gz",
"status": "inactive",
"is_active": false,
"created_at": "2025-02-20T10:00:00Z",
"deployed_at": "2025-02-20T10:01:15Z"
}
]
}
Features:
- Ordered by version (newest first)
- Shows active vs inactive deployments
- Includes S3 storage keys
- Deployment timestamps
Rollback
Restore a previous deployment version.
POST /api/functions/:id/rollback
Request:
{
"version": 2
}
Response:
{
"message": "Function rolled back successfully",
"function": {
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "my-function",
"status": "active",
"active_version": 2
}
}
What Happens:
- Previous active deployment marked as inactive
- Specified version marked as active
- Function container restarted with rolled-back version
- All invocations use the restored version
Use Cases:
- Revert breaking changes
- Restore stable version after failed deployment
- A/B testing different versions
- Emergency rollback
Deletion Management
Functions scheduled for deletion enter a grace period before permanent removal.
Pending Deletions
View all functions scheduled for deletion.
GET /api/functions/pending-deletions
Response:
{
"pending_deletions": [
{
"id": "pending-deletion-uuid",
"function_uuid": "550e8400-e29b-41d4-a716-446655440000",
"function_name": "my-function",
"function_status": "pending_deletion",
"image_tag": "registry/my-function:v3",
"reason": "user_requested",
"deletion_date": "2025-03-01T00:00:00Z",
"days_remaining": 7,
"scheduled_at": "2025-02-21T10:30:00Z"
}
],
"count": 1
}
Deletion Reasons:
- user_requested - User initiated deletion
- stale_function - Inactive for extended period
- quota_exceeded - Account quota management
Check Deletion Status
Get deletion status for a specific function.
GET /api/functions/:uuid/deletion-status
Response:
{
"function_uuid": "550e8400-e29b-41d4-a716-446655440000",
"function_name": "my-function",
"has_pending_deletion": true,
"deletion_info": {
"id": "pending-deletion-uuid",
"image_tag": "registry/my-function:v3",
"reason": "user_requested",
"deletion_date": "2025-03-01T00:00:00Z",
"days_remaining": 7,
"scheduled_at": "2025-02-21T10:30:00Z"
}
}
Cancel Deletion
Cancel a pending deletion and restore function to active status.
POST /api/functions/:uuid/cancel-deletion
Response:
{
"success": true,
"message": "Deletion cancelled successfully",
"function": {
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "my-function",
"status": "active"
}
}
What Happens:
- All pending deletion records marked as cancelled
- Function status restored to active
- Function remains operational
- Deletion can be rescheduled if needed
Status Lifecycle
┌─────────────────────────────────────────────┐ │ │ │ init → building → active │ │ ↑ ↓ │ │ └─────────┘ (redeploy) │ │ ↓ │ │ pending_deletion │ │ ↓ │ │ deleted │ │ │ └─────────────────────────────────────────────┘
Status Definitions:
- init - Function initialized, awaiting first deployment
- building - Container image being built
- active - Function deployed and accepting invocations
- pending_deletion - Scheduled for deletion
- deleted - Permanently removed
Best Practices
Initialization
- Initialize functions before deployment
- Use descriptive, unique function names
- Store function UUID securely in your deployment config
Versioning
- Keep deployment history for rollback capability
- Test new versions before promoting to production
- Document version changes for team awareness
Rollback Strategy
- Monitor new deployments closely
- Have rollback plan ready for critical functions
- Test rollback procedure in staging environment
Deletion Management
- Review pending deletions regularly
- Cancel accidental deletions promptly
- Use grace period to backup important data
Integration Example
// 1. Initialize function
final initResponse = await apiClient.initFunction('my-function');
final functionId = initResponse['id'];
// 2. Deploy function
await apiClient.deployFunction(
functionId: functionId,
archive: archiveFile,
env: {'KEY': 'value'},
);
// 3. View deployment history
final deployments = await apiClient.getDeployments(
functionId: functionId,
page: 1,
perPage: 10,
);
// 4. Rollback if needed
await apiClient.rollbackFunction(
functionId: functionId,
version: 2,
);
// 5. Check deletion status
final deletionStatus = await apiClient.getDeletionStatus(
functionId: functionId,
);
// 6. Cancel deletion if needed
if (deletionStatus['has_pending_deletion']) {
await apiClient.cancelDeletion(functionId: functionId);
}
Next Steps
- Read API Reference for complete endpoint documentation
- Check Function Execution for invocation details
- Review Statistics & Monitoring for performance tracking