Sample code

更新时间:
复制 MD 格式

Function Compute provides ready-to-use sample code for common runtimes, web frameworks, and use cases. Browse the categories below to find a starting point that matches your tech stack or scenario, then follow the README.md in each repository to deploy it.

Hello World

Each Hello World sample contains the minimum code needed to create and invoke a Function Compute function. Samples are organized by runtime type.

Built-in runtimes

LanguageRepository
Node.jsfc-node
Javafc-java
Pythonfc-python
PHPfc-php
Gofc-golang
.NET Corefc-dotnetcore

Custom runtimes

Use a custom runtime to run languages or runtime versions not supported by built-in runtimes.

LanguageRepository
Gogolang
Javajava
Node.jsnodejs
Pythonpython

Custom containers

Package your function as a container image to bring your own OS, dependencies, and toolchain.

LanguageRepository
Gogolang
Javajava
Node.jsnodejs
Pythonpython

Web applications

Each sample shows how to run a web framework on Function Compute and handle HTTP requests. Pick the framework that matches your stack.

Node.js

FrameworkDescription
ExpressMinimal, unopinionated Node.js web framework
EggEnterprise Node.js framework built on Koa
Next.jsReact framework with server-side rendering
Nuxt.jsVue framework with server-side rendering
HapiConfiguration-centric Node.js framework
KoaLightweight middleware-based Node.js framework
NestTypeScript-first Node.js framework
ExcalidrawCollaborative whiteboard application
FastifyHigh-performance Node.js web framework
Think.jsFull-featured Node.js MVC framework

Python

FrameworkDescription
FlaskLightweight Python web microframework
TornadoAsynchronous Python web framework
Web.pySimple, minimal Python web framework
DjangoBatteries-included Python web framework
FastAPIModern Python API framework with automatic OpenAPI docs

PHP

FrameworkDescription
ThinkPHPFull-featured PHP MVC framework
LaravelPHP framework with an expressive syntax

Go

FrameworkDescription
GinHigh-performance Go HTTP framework
BeegoFull-featured MVC framework for Go

Java

FrameworkDescription
SpringBootProduction-ready Java application framework

Other

FrameworkDescription
NginxServes static content or acts as a forward proxy
Nginx reverse proxyRoutes incoming requests to one or more upstream services

Static website applications

SampleDescription
DocusaurusBuilds and serves a Docusaurus documentation site on Function Compute

AI scenarios

SampleDescription
PyTorchRuns PyTorch model inference in a Function Compute function
TensorFlowRuns TensorFlow model inference in a Function Compute function
OCRExtracts text from images using optical character recognition
Object detectionDetects and classifies objects in images
GPU-accelerated applicationsRuns compute-intensive workloads on GPU instances

Audio and video processing

SampleDescription
Custom audio and video processingProcesses audio and video files using a custom FFmpeg pipeline
Audio and video transcodingTranscodes media files to different formats or resolutions
Audio and video processing workflowsOrchestrates multi-step media processing as a serverless workflow

Others

SampleDescription
Microsoft Word to PDFConverts Word documents to PDF on upload
PDF to imageConverts PDF pages to image files