Skip to main content

Cloud Function Management

Cloud functions are one of the core features of the cloud development platform. Effective management of cloud functions can improve the performance, reliability, and security of applications. This document will guide you on how to comprehensively manage the lifecycle of cloud functions, including operations such as creating, configuring, deploying, monitoring, and deleting.

Contents

Management Methods

You can manage cloud functions in the following two ways:

Different management methods are suitable for different scenarios. Console Management is ideal for quick operations and visual configuration, while Command-line Management is better suited for automated deployment and batch operations.

Create Cloud Function

Create via Console

  1. Log in to the CloudBase platform and access the Cloud Function Management Page
  2. Click the 'Create Cloud Function' button
  3. Fill in the function name, runtime environment, function description, and other information
  4. Select a function template or start writing code from scratch
  5. Click 'OK' to complete the creation

Create Cloud Function Interface

Create via CLI

Using the CloudBase CLI tool, you can create and deploy cloud functions with the following command:

tcb functions:deploy [functionName] --code ./function-code

Development and Deployment

Online Editing and Deployment

You can directly edit cloud function code in the CloudBase console:

  1. Select the target function on the Cloud Function Management Page
  2. Modify the code in the code editor
  3. Click the 'Save and Deploy' button to complete the deployment

Online Function Code Editing

Deploy via Code Package Upload

For more complex projects, you can package and upload the code:

  1. Package the function code and dependencies into a ZIP file
  2. On the cloud function details page, select 'Upload ZIP Package'
  3. Select and upload the local ZIP file
  4. Click 'Save and Deploy' to complete the deployment
Note

The root directory of the ZIP package should contain the entry file, such as index.js in the Node.js environment.

Update Code via CLI

Update cloud function code using the CLI tool:

tcb functions:code:update <functionName> --code ./function-code

Function Configuration

On the Cloud Function Management Page, select the target function and click the 'Configuration' tab to adjust the following configuration items:

Basic Configuration

ItemDescriptionDefault ValueAllowed Values
Memory ConfigurationMaximum memory limit for cloud function runtime256MB128MB - 2048MB
TimeoutMaximum function execution time; function will be forcibly terminated upon timeout20s1s - 900s
Environment VariablesEnvironment variables defined as key/value pairsNoneCustom
Note

Memory configuration affects the function's performance and billing. Please set it appropriately based on actual requirements.

Network Configuration

Public Network Access

Cloud Functions have public network access enabled by default. You can choose to disable it based on security requirements. Once disabled, the function will not be able to access public network resources.

Intranet Access (VPC Configuration)

You can configure Cloud Functions to access the VPC private network:

  • Not configured VPC: Function instances run in an isolated network environment with public network access capability.
  • Configured VPC: Function instances run in the specified VPC network and can access resources within the VPC.
Note

Fixed Egress IP

After enabling this feature, Cloud Functions will be assigned a fixed public egress IP. This IP will be shared with other functions that have this feature enabled in the same namespace.

Note

The fixed egress IP feature will take effect only when public network access is enabled for Cloud Functions.

Update Configuration via CLI

Update cloud function configuration using the CLI tool:

tcb functions:config:update [functionName] --memory 512 --timeout 60

Function Monitoring

View Runtime Logs

You can view the runtime logs of cloud functions through the following methods:

  1. On the Cloud Function details page, select the Logs tab
  2. Set the time range and log level
  3. View function execution logs

View logs via CLI:

tcb functions:log <functionName> --limit 20

Monitoring Metrics

On the Cloud Function details page, in the Monitoring tab, you can view the following key metrics:

  • Invocation count
  • Error count
  • Average execution duration
  • Memory usage

Deleting Cloud Function

Delete via Console

  1. Locate the target function on the Cloud Function Management Page
  2. Click "More" → "Delete"
  3. In the confirmation dialog box, enter the function name to confirm deletion.
Warning

Deleting a cloud function is irreversible. After deletion, the function will be inaccessible. Please proceed with caution.

Delete via CLI

Use the CLI tool to delete cloud function:

tcb functions:delete [functionName]

Managing Cloud Functions with CLI Tools

The CloudBase CLI tool provides comprehensive cloud function management commands, enabling automated deployment and management:

# List cloud functions
tcb functions:list [options]

# Download Cloud Function Code
tcb functions:download [options] <functionName> [dest]

# Deploy Cloud Function
tcb functions:deploy [options] [functionName]

# Delete Cloud Function
tcb functions:delete [options] [functionName]

# Get Cloud Function Information
tcb functions:detail [options] [functionName]

# Update Cloud Function Code
tcb functions:code:update [options] <functionName>

# Update Cloud Function Configuration
tcb functions:config:update [options] [functionName]

# Copy Cloud Function
tcb functions:copy [options] <functionName> <newFunctionName>

# Print Cloud Function Logs
tcb functions:log [options] <functionName>

# Create Cloud Function Trigger
tcb functions:trigger:create [options] [functionName]

# Delete Cloud Function Trigger
tcb functions:trigger:delete [options] [functionName] [triggerName]

# Trigger Cloud-Deployed Function
tcb functions:invoke [options] [functionName]

# Run Cloud Functions Locally (Currently only supports Node)
tcb functions:run [options]

For more detailed information and advanced usage, please refer to the CloudBase CLI tool documentation.

Frequently Asked Questions

What to do if Cloud Function deployment fails?

  1. Check the code for syntax errors
  2. Confirm whether the dependency packages are compatible with the cloud function environment
  3. Check the deployment logs to identify the specific error cause
  4. Try to reduce the deployment package size, as cloud function deployment packages have size limits

How to resolve cloud function execution timeout?

  1. Increase the function timeout configuration
  2. Optimize code execution efficiency
  3. For long-running tasks, consider splitting them into multiple functions or using asynchronous execution.

How to handle cloud function cold start issues?

  1. Keep function code concise and reduce unnecessary dependencies
  2. Use provisioned concurrency instances
  3. Periodically warm up functions to keep them active

How do cloud functions access databases?

Cloud functions can directly access the CloudBase database via the SDK without additional authentication configuration. Sample code:

const tcb = require('@cloudbase/node-sdk');
const app = tcb.init();
const db = app.database();

exports.main = async (event, context) => {
const collection = db.collection('users');
const result = await collection.get();
return result;
};

For more cloud function related questions, please refer to Cloud Function FAQ.