Cloud Native 17 min read

Master Serverless on Alibaba Cloud: Create, Deploy, Debug Functions Step‑by‑Step

This guide walks you through the entire lifecycle of a Serverless application on Alibaba Cloud, covering function creation via the console, project initialization and deployment with Serverless Devs, various debugging techniques—including online, breakpoint, proxy, and local debugging—and best practices for dependency management and performance testing.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Master Serverless on Alibaba Cloud: Create, Deploy, Debug Functions Step‑by‑Step

Overview

This article provides a comprehensive tutorial on developing, deploying, and debugging Serverless applications on Alibaba Cloud Function Compute, using both the web console and the Serverless Devs developer tool.

Creating Functions via the Console

Register and log in to an Alibaba Cloud account.

Navigate to the Function Compute (FaaS) product.

Click the “Create Function” button.

Configure the function name and runtime environment.

Complete creation and test the function.

Images illustrate the product homepage, service creation, and function creation pages.

Functions are organized into services, which provide benefits such as logical grouping, shared configuration (VPC, NAS, logs), environment isolation (e.g., dev, test, prod), and easier management of large numbers of functions.

Creating and Deploying with Serverless Devs

Serverless Devs is an open‑source tool that streamlines multi‑cloud Serverless development. The workflow includes:

Install the tool: npm install -g @Serverless-devs/s Configure Alibaba Cloud credentials:

s config add --AccessKeyID AccessKeyID --AccessKeySecret AccessKeySecret --AccountID AccountID

Initialize a template project: s init node.js12-http -d fc-hello-world-demo Enter the project directory and deploy: cd fc-hello-world-demo && s deploy After deployment, you can invoke the function ( s invoke), view details ( s info), and manage the application via the Serverless Devs desktop client, which supports one‑click performance testing, debugging, and multi‑dimensional metric viewing.

Debugging Serverless Applications

Online Debugging

Use the console’s “Code Execute” feature to run code directly and optionally set events to simulate triggers.

Breakpoint Debugging

Alibaba Cloud offers remote debugging. After creating a function, enable remote debugging and click “Start Debugging” to enter a breakpoint debugging interface.

Proxy (端云联调) Debugging

Serverless Devs can create auxiliary services and functions based on the Yaml configuration, allowing local code to interact with online resources (VPC, RDS, NAS, etc.). The workflow:

Run s proxied setup to provision auxiliary resources.

Invoke the local function with s proxied invoke (or via VSCode).

After debugging, clean up with s proxied cleanup.

Remote Debugging

Use the instance command to log into the online container and perform low‑level troubleshooting with tools such as tcpdump, coredump, or jmap. apt-get update && apt-get install tcpdump Capture network traffic, upload the capture file to OSS, and analyze it locally.

Local Debugging

Command‑line tools (e.g., Funcraft, Serverless Framework) and IDE plugins (VSCode) enable local debugging. Example using Docker for a Python function:

docker run -v $(pwd):/code -w /code python:3.6 python -m unittest

VSCode plugin allows setting breakpoints after configuring the Alibaba Cloud account.

Other Debugging Approaches

For web frameworks like Bottle, add a conditional entry point:

if __name__ == '__main__':
    bottle.run(host='localhost', port=8080, debug=True)

For event‑driven functions, construct a mock event JSON and invoke the handler locally.

import json

def handler(event, context):
    print(event)

# mock event example
event = {"events": [{"eventName": "ObjectCreated:PutObject", "eventSource": "acs:oss", ...}]}
handler(json.dumps(event), None)

Dependency Installation and Project Build

Serverless applications often face dependency compatibility issues. Alibaba Cloud Function Compute provides environment details (Linux kernel 4.4.24‑2.al7.x86_64, Docker base images python:2.7 and python:3.6).

Three common methods to install dependencies:

Manually set up a matching environment locally and install dependencies.

Use Serverless Devs with Docker to build in an environment identical to the cloud runtime: s build --use-docker, then s deploy.

Leverage the WebIDE console to run commands and install dependencies directly online.

These approaches ensure that compiled binaries and native libraries work correctly when the function runs on the cloud.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingCloud NativeServerlessAlibaba CloudFunction Compute
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.