Memasukkan semua dependensi ke dalam paket penyebaran setiap fungsi menghasilkan arsip berukuran besar dan upaya duplikasi lintas fungsi. Function Compute menyediakan lapisan publik resmi untuk runtime dan pustaka dependensi umum. Tambahkan lapisan publik ini untuk berbagi dependensi antar fungsi tanpa perlu membangun ulang setiap kali.
Lapisan publik
Tabel berikut mencantumkan lapisan publik yang tersedia berdasarkan kategori. Untuk daftar lengkapnya, lihat Lapisan publik. Jika Anda memerlukan lapisan yang tidak tercantum, hubungi kami.
Runtime kustom
Lapisan-lapisan ini menyediakan lingkungan runtime untuk runtime kustom seperti Python 3.10 dan Node.js 17. Beberapa lapisan juga mencakup pustaka dependensi umum—misalnya, Python310-Package-Collection mencakup paket Python yang sering digunakan.
| Public layer | Compatible runtime | Description | References |
|---|---|---|---|
| PHP81-Debian10 | Custom.Debian10 | PHP 8.1 Debian 10 runtime layer | README.md |
| PHP80-Debian10 | Custom.Debian10 | PHP 8.0 Debian 10 runtime layer | README.md |
| Nginx | Custom.Debian10 | Nginx Debian 10 runtime layer | README.md |
| Python310 | Custom, Custom.Debian10 | Python 3.10.5 runtime layer | README.md |
| Python310-Package-Collection | Custom.Debian10 | A collection of common dependency libraries for the Python 3.10 runtime | README.md |
| Python39 | Custom, Custom.Debian10 | Python 3.9.13 runtime layer | README.md |
| Python39-Package-Collection | Custom, Custom.Debian10 | A collection of common dependency libraries for the Python 3.9 runtime | README.md |
| Python38 | Custom, Custom.Debian10 | Python 3.8.13 runtime layer | README.md |
| Python38-Package-Collection | Custom, Custom.Debian10 | A collection of common dependency libraries for the Python 3.8.13 runtime | README.md |
| Python36 | Custom | Python 3.6.15 runtime layer | README.md |
| Python36-Package-Collection | Custom | A collection of common dependency libraries for the Python 3.6.15 runtime | README.md |
| Dotnet6 | Custom, Custom.Debian10 | ASP.NET 6.0.5 runtime layer | README.md |
| PHP72 | Custom | PHP 7.2 runtime layer | README.md |
| Java8 | Custom.Debian10 | Java 8 runtime layer | README.md |
| Java11 | Custom, Custom.Debian10 | Java 11 runtime layer | README.md |
| Java17 | Custom, Custom.Debian10 | Java 17 runtime layer | README.md |
| Java21 | Custom.Debian10 | Java 21 runtime layer | README.md |
| Nodejs20 | Custom.Debian10 | Node.js 20 runtime layer | README.md |
| Nodejs18 | Custom.Debian10 | Node.js 18 runtime layer | README.md |
| Nodejs17 | Custom | Node.js 17 runtime layer | README.md |
| Nodejs16 | Custom, Custom.Debian10 | Node.js 16 runtime layer | README.md |
| Nodejs14 | Custom | Node.js 14 runtime layer | README.md |
| Nodejs12 | Custom | Node.js 12 runtime layer | README.md |
| Go1 | Custom.Debian10 | Go 1 runtime layer | README.md |
| Go118 | Custom | Go 1.x runtime layer | README.md |
Pustaka dependensi umum
| Public layer | Compatible runtime | Description | Core library version | References |
|---|---|---|---|---|
| Python310-OSS2 | Python 3.10, Custom.Debian10 | oss2: OSS SDK for Python | - | README.md |
| Python39-OSS2 | Python 3.9, Custom.Debian10 | oss2: OSS SDK for Python | - | README.md |
| Python310-TensorFlow2x | Python 3.10, Custom.Debian10 | An open source machine learning framework (CPU edition) | tensorflow==2.15.0.post1 | README.md |
| Python3x-PyMongo4x | Python 3.10, Custom.Debian10 | An open source scientific computing library | PyMongo==4.6.1 | README.md |
| Python3x-Pandas2x | Python 3.9, Custom.Debian10 | An open source data analysis and processing tool based on NumPy | pandas==2.2.1 | README.md |
| Python310-PyTorch2x | Python 3.10, Custom.Debian10 | An open source machine learning framework (CPU edition) | torch==2.2.1+cpu | README.md |
| Python39-Pandas1x | Python 3.9, Custom, Custom.Debian10 | An open source data analysis and processing tool based on NumPy | pandas==1.4.3 | README.md |
| Python39-SciPy1x | Python 3.9, Custom, Custom.Debian10 | An open source scientific computing library | scipy==1.9.0, numpy==1.23.2 | README.md |
| Python36-SciPy1x | Python 3.6, Custom | An open source scientific computing library | scipy-1.5.4, numpy-1.19.5 | README.md |
| Python39-PyTorch1x | Python 3.9, Custom, Custom.Debian10 | An open source machine learning framework (CPU edition) | torch==1.12.1+cpu, torchaudio==0.12.1+cpu, torchvision==0.13.1+cpu | README.md |
| Python36-PyTorch1x | Python 3.6, Custom | An open source machine learning framework (CPU edition) | torch==1.10.2+cpu, torchaudio==0.10.2+cpu, torchvision==0.11.3+cpu | README.md |
| Python3-Flask2x | Python 3.9, Python 3.10, Custom, Custom.Debian10 | A Python-based lightweight web framework | flask-v2.2.2 | README.md |
| Nodejs-Puppeteer17x | Node.js 16, Node.js 14, Custom, Custom.Debian10 | A Headless Chrome tool | puppeteer-v17.1.0 | README.md |
| Nodejs-Puppeteer10x | Node.js 14, Node.js 12, Node.js 10, Custom | A Headless Chrome tool | puppeteer-v10.2.0 | README.md |
| Nodejs-Puppeteer19x | Custom.Debian10 | A Headless Chrome tool | puppeteer-v19.8.5 | README.md |
| Python310-Opencv4x | Python 3.10, Custom.Debian10 | A cross-platform library for computer vision | opencv_python-4.7.0.68 | README.md |
| Python38-Playwright | Custom.Debian10 | A tool for web page automation | playwright==1.31.1 | README.md |
| Poppler22x-Pdf2image | Python 3.10 | A library for rendering PDF documents | pdf2image-1.16.3, poppler-22.12.0 | README.md |
| SQLite3 | Python 3.9, Node.js 16, Node.js 14, Java 11, Java 8, Custom | A lightweight in-process relational database | 3.41.1 | README.md |
| FFmpeg6x | Python 3.10, Python 3.9, Node.js 16, Node.js 14, Java 11, Java 8, Custom, Custom.Debian10 | An open source toolkit for recording, converting, and streaming audio and video | 6.0 | README.md |
| ServerlessDevs | Python 3.10, Python 3.9, Python 3, Node.js 16, Node.js 14, Java 11, Java 8, Go 1, .NetCore 3.1, PHP 7.2, Custom, Custom.Debian10 | An open source serverless platform that provides a robust set of tools for developers | 2.1.14 | README.md |
Web frameworks
| Public layer | Compatible runtime | Core library version | References |
|---|---|---|---|
| Python3-Flask2x | Python 3.9, Python 3.10, Custom, Custom.Debian10 | flask-2.2.2 | README.md |
Alibaba Cloud SDKs
| Public layer | Compatible runtime | Description | References |
|---|---|---|---|
| Python310-Aliyun-SDK | Python 3.10, Custom.Debian10 | Common Alibaba Cloud SDKs for Python 3.10 | README.md |
| Python39-Aliyun-SDK | Python 3.9, Custom | Common Alibaba Cloud SDKs for Python 3.9 | README.md |
| Python36-Aliyun-SDK | Python 3.6, Custom | Common Alibaba Cloud SDKs for Python 3.6 | README.md |
| Nodejs-Aliyun-SDK | Node.js 20, Node.js 18, Node.js 16, Node.js 14, Custom, Custom.Debian10 | Common Alibaba Cloud SDKs (Node.js 20, Node.js 18, Node.js 16, and Node.js 14) | README.md |
| Aliyun-DataX | Python 3.6, Python 3.9, Custom, Custom.Debian10 | Open source edition of Alibaba Cloud DataWorks Data Integration | README.md |
Cara kerja lapisan
Satu fungsi mendukung hingga lima lapisan secara total, termasuk lapisan kustom dan lapisan publik. Saat beberapa lapisan dikonfigurasi, Function Compute menggabungkan isinya ke dalam direktori /opt dalam urutan terbalik. Jika dua lapisan berisi file dengan nama yang sama, file dari lapisan yang dikonfigurasi pertama akan mengambil prioritas dibandingkan file pada lapisan berikutnya.
Tambahkan lapisan publik di konsol
Prasyarat
Sebelum memulai, pastikan Anda telah:
Membuat fungsi Function Compute. Untuk membuatnya, lihat Buat fungsi.
Tambahkan lapisan
Masuk ke Konsol Function Compute. Di panel navigasi sebelah kiri, klik Functions.
Di bilah navigasi atas, pilih wilayah. Pada halaman Functions, klik nama fungsi yang ingin Anda konfigurasi.
Di halaman detail fungsi, klik tab Configurations.
Di pohon navigasi sebelah kiri, klik Layers, lalu klik Modify.
Di panel Layers, klik + Add Layer dan pilih Add Official Common Layer. Pilih lapisan dari daftar drop-down Official Common Layer dan versi dari daftar drop-down Layer Version, lalu klik Deploy.
Tambahkan lapisan publik menggunakan Serverless Devs
Prasyarat
Sebelum memulai, pastikan Anda telah:
Menginstal Serverless Devs dan mengonfigurasi Docker. Lihat Quick start.
Mengonfigurasi Serverless Devs dengan kredensial Anda. Lihat Configure Serverless Devs.
Tambahkan lapisan
Jalankan perintah berikut untuk menampilkan daftar lapisan publik resmi di suatu wilayah:
s cli fc layer list --official --region cn-hangzhouOutput-nya mencantumkan lapisan yang tersedia beserta ARN-nya. Salin ARN lapisan yang ingin Anda gunakan.
- layerName: Python39-Aliyun-SDK arn: acs:fc:cn-hangzhou:official:layers/Python39-Aliyun-SDK/versions/3 version: 3 acl: 1 description: Python3.9 Aliyun SDK layer. compatibleRuntime: - custom - python3.9 - custom.debian10 - layerName: Python39-Package-Collection arn: acs:fc:cn-hangzhou:official:layers/Python39-Package-Collection/versions/3 version: 3 acl: 1 description: Python3.9 package collection layer. compatibleRuntime: - custom - custom.debian10Bidang utama dalam output:
Field Description layerNameNama lapisan versionVersi lapisan arnARN versi lapisan, digunakan saat menyambungkan lapisan ke fungsi aclKontrol akses: 0= privat,1= publikdescriptionDeskripsi singkat tentang lapisan compatibleRuntimeRuntime yang didukung oleh lapisan ini Di direktori proyek Anda, buat file
s.yamldan tambahkan ARN lapisan ke bidanglayers.edition: 3.0.0 name: hello-world-app access: "default" vars: # The global variables region: "cn-hangzhou" resources: hello_world: component: fc3 # The component name. actions: # The custom execution logic. props: region: ${vars.region} functionName: "emoji" description: 'this is a layer demo' runtime: "python3.9" code: ./code handler: index.handler memorySize: 512 timeout: 60 internetAccess: true layers: # The ARNs of the layers attached to the function. - acs:fc:cn-hangzhou:official:layers/Python39-Aliyun-SDK/versions/3Buat direktori
codedi direktori proyek Anda dan letakkan kode fungsi Anda di dalamnya.Jalankan perintah berikut untuk menyebar fungsi dengan lapisan yang telah dikonfigurasi:
s deploy
Langkah selanjutnya
Kelola lapisan secara terprogram menggunakan operasi API CreateFunction dan UpdateFunction.
Jika Anda melihat error
xxx is not supported by layersaat mengonfigurasi lapisan, lihat Apa yang harus saya lakukan jika muncul pesan "xxx is not supported by layer" saat mengonfigurasi lapisan untuk fungsi?