Phase 2: veFaaS Function Service Support
Parent Epic: #179
Depends on: Phase 1 (#PHASE1)
Overview
Implement full CRUD support for Volcengine's Function Service (veFaaS), enabling deploy, update, and destroy of serverless functions.
Service Information
Supported Runtimes
python/3.10, python/3.9, python/3.8
nodejs/18, nodejs/16, nodejs/14
golang/1
java/11, java/8
Tasks
1. Type Definitions (vefaasTypes.ts)
// src/stack/volcengineStack/vefaasTypes.ts
export type VefaasFunctionConfig = {
functionName: string;
runtime: string;
handler: string;
memoryMb: number;
requestTimeout: number;
environmentVariables?: Record<string, string>;
description?: string;
vpcConfig?: {
vpcId: string;
subnetIds: string[];
securityGroupIds: string[];
};
tosMountConfig?: {
bucketName: string;
mountPath: string;
};
};
export type VefaasFunctionInfo = {
functionId: string;
functionName: string;
runtime: string;
handler: string;
memoryMb: number;
requestTimeout: number;
environmentVariables?: Record<string, string>;
status: string;
createdTime: string;
lastModifiedTime: string;
};
2. Client Operations (vefaasOperations.ts)
// src/common/volcengineClient/vefaasOperations.ts
export const createVefaasOperations = (client: VefaasClient) => ({
createFunction: async (config: VefaasFunctionConfig, codePath: string): Promise<void> => {
const code = fs.readFileSync(codePath);
const command = new CreateFunctionCommand({
Name: config.functionName,
Runtime: config.runtime,
Handler: config.handler,
MemoryMb: config.memoryMb,
RequestTimeout: config.requestTimeout,
Code: { ZipFile: code.toString('base64') },
Envs: config.environmentVariables,
});
await client.send(command);
},
getFunction: async (functionName: string): Promise<VefaasFunctionInfo | null> => {
// Implement with error handling for NotFound
},
updateFunctionConfiguration: async (config: VefaasFunctionConfig): Promise<void> => { ... },
updateFunctionCode: async (functionName: string, codePath: string): Promise<void> => { ... },
deleteFunction: async (functionName: string): Promise<void> => { ... },
listFunctions: async (): Promise<VefaasFunctionInfo[]> => { ... },
});
3. Resource Implementation (vefaasResource.ts)
Implement four lifecycle functions:
export const createResource = async (
context: Context,
fn: FunctionDomain,
state: StateFile,
): Promise<StateFile> => {
// 1. Create dependent resources (IAM role if needed)
// 2. Upload code to TOS if large
// 3. Create function
// 4. Update state
};
export const readResource = async (
context: Context,
functionName: string
): Promise<VefaasFunctionInfo | null> => { ... };
export const updateResource = async (
context: Context,
fn: FunctionDomain,
state: StateFile,
): Promise<StateFile> => { ... };
export const deleteResource = async (
context: Context,
functionName: string,
logicalId: string,
state: StateFile,
): Promise<StateFile> => { ... };
4. Planner (vefaasPlanner.ts)
5. Executor (vefaasExecutor.ts)
6. Integration
Function Configuration Mapping
| YAML Field |
veFaaS API Field |
Notes |
name |
Name |
Required |
code.runtime |
Runtime |
e.g., "nodejs/18" |
code.handler |
Handler |
e.g., "index.handler" |
code.path |
Code.ZipFile |
Base64 encoded |
memory |
MemoryMb |
Default: 128 |
timeout |
RequestTimeout |
Default: 30 |
environment |
Envs |
Key-value pairs |
network.vpc_id |
VpcConfig.VpcId |
Optional |
network.subnet_ids |
VpcConfig.SubnetIds |
Optional |
Sample Configuration
# samples/volcengine-poc-function.yml
version: 0.1.0
provider:
name: volcengine
region: cn-beijing
app: insight-poc
service: insight-poc-vefaas
functions:
hello_function:
name: insight-poc-hello
code:
runtime: nodejs/18
handler: index.handler
path: ./artifacts/function.zip
memory: 256
timeout: 30
environment:
NODE_ENV: production
Acceptance Criteria
Must Have
Should Have
Nice to Have
Test Cases
describe('vefaasResource', () => {
it('should create a function with minimal config', async () => { ... });
it('should create a function with environment variables', async () => { ... });
it('should update function configuration', async () => { ... });
it('should update function code', async () => { ... });
it('should delete a function', async () => { ... });
it('should handle function not found on delete', async () => { ... });
it('should handle partial failure and save state', async () => { ... });
});
References
Estimated Effort
Large (5-7 days)
Phase 2: veFaaS Function Service Support
Parent Epic: #179
Depends on: Phase 1 (#PHASE1)
Overview
Implement full CRUD support for Volcengine's Function Service (veFaaS), enabling deploy, update, and destroy of serverless functions.
Service Information
@volcengine/vefaasSupported Runtimes
Tasks
1. Type Definitions (
vefaasTypes.ts)2. Client Operations (
vefaasOperations.ts)3. Resource Implementation (
vefaasResource.ts)Implement four lifecycle functions:
4. Planner (
vefaasPlanner.ts)generateVefaasPlan()function5. Executor (
vefaasExecutor.ts)executeVefaasPlan()function6. Integration
volcengineStack/planner.tsto include vefaas plannervolcengineStack/deployer.tsto execute vefaas planvolcengineStack/destroyer.tsto delete functionsFunction Configuration Mapping
nameNamecode.runtimeRuntimecode.handlerHandlercode.pathCode.ZipFilememoryMemoryMbtimeoutRequestTimeoutenvironmentEnvsnetwork.vpc_idVpcConfig.VpcIdnetwork.subnet_idsVpcConfig.SubnetIdsSample Configuration
Acceptance Criteria
Must Have
si deploy -f samples/volcengine-poc-function.ymlcreates function in Volcenginesi deploy(second run) detects no changessi deploywith code changes updates function codesi deploywith config changes updates function configurationsi destroyremoves function and cleans up statenpm testpasses for vefaas-related testsShould Have
Nice to Have
Test Cases
References
Estimated Effort
Large (5-7 days)