すべての依存関係を各関数のデプロイメントパッケージに含めると、アーカイブが大きくなり、関数間で作業が重複します。Function Compute は、一般的なランタイムと依存ライブラリのために公式パブリックレイヤーを提供しています。パブリックレイヤーを追加することで、毎回再ビルドすることなく、関数間で依存関係を共有できます。
パブリックレイヤー
以下の表は、利用可能なパブリックレイヤーをカテゴリ別に示しています。完全なリストについては、「パブリックレイヤー」をご参照ください。リストにないレイヤーが必要な場合は、お問い合わせください。
カスタムランタイム
これらのレイヤーは、Python 3.10 や Node.js 17 などのカスタムランタイム向けの実行環境を提供します。一部のレイヤーには、一般的な依存ライブラリもバンドルされています。たとえば、Python310-Package-Collection には、頻繁に使用される Python パッケージが含まれています。
| パブリックレイヤー | 互換性のあるランタイム | 説明 | リファレンス |
|---|---|---|---|
| PHP81-Debian10 | Custom.Debian10 | PHP 8.1 Debian 10 ランタイムレイヤー | README.md |
| PHP80-Debian10 | Custom.Debian10 | PHP 8.0 Debian 10 ランタイムレイヤー | README.md |
| Nginx | Custom.Debian10 | Nginx Debian 10 ランタイムレイヤー | README.md |
| Python310 | Custom, Custom.Debian10 | Python 3.10.5 ランタイムレイヤー | README.md |
| Python310-Package-Collection | Custom.Debian10 | Python 3.10 ランタイム用の一般的な依存ライブラリのコレクション | README.md |
| Python39 | Custom, Custom.Debian10 | Python 3.9.13 ランタイムレイヤー | README.md |
| Python39-Package-Collection | Custom, Custom.Debian10 | Python 3.9 ランタイム用の一般的な依存ライブラリのコレクション | README.md |
| Python38 | Custom, Custom.Debian10 | Python 3.8.13 ランタイムレイヤー | README.md |
| Python38-Package-Collection | Custom, Custom.Debian10 | Python 3.8.13 ランタイム用の一般的な依存ライブラリのコレクション | README.md |
| Python36 | Custom | Python 3.6.15 ランタイムレイヤー | README.md |
| Python36-Package-Collection | Custom | Python 3.6.15 ランタイム用の一般的な依存ライブラリのコレクション | README.md |
| Dotnet6 | Custom, Custom.Debian10 | ASP.NET 6.0.5 ランタイムレイヤー | README.md |
| PHP72 | Custom | PHP 7.2 ランタイムレイヤー | README.md |
| Java8 | Custom.Debian10 | Java 8 ランタイムレイヤー | README.md |
| Java11 | Custom, Custom.Debian10 | Java 11 ランタイムレイヤー | README.md |
| Java17 | Custom, Custom.Debian10 | Java 17 ランタイムレイヤー | README.md |
| Java21 | Custom.Debian10 | Java 21 ランタイムレイヤー | README.md |
| Nodejs20 | Custom.Debian10 | Node.js 20 ランタイムレイヤー | README.md |
| Nodejs18 | Custom.Debian10 | Node.js 18 ランタイムレイヤー | README.md |
| Nodejs17 | Custom | Node.js 17 ランタイムレイヤー | README.md |
| Nodejs16 | Custom, Custom.Debian10 | Node.js 16 ランタイムレイヤー | README.md |
| Nodejs14 | Custom | Node.js 14 ランタイムレイヤー | README.md |
| Nodejs12 | Custom | Node.js 12 ランタイムレイヤー | README.md |
| Go1 | Custom.Debian10 | Go 1 ランタイムレイヤー | README.md |
| Go118 | Custom | Go 1.x ランタイムレイヤー | README.md |
共通依存ライブラリ
| パブリックレイヤー | 互換性のあるランタイム | 説明 | コアライブラリのバージョン | リファレンス |
|---|---|---|---|---|
| Python310-OSS2 | Python 3.10, Custom.Debian10 | oss2: Python 用 OSS SDK | - | README.md |
| Python39-OSS2 | Python 3.9, Custom.Debian10 | oss2: Python 用 OSS SDK | - | README.md |
| Python310-TensorFlow2x | Python 3.10, Custom.Debian10 | オープンソースの機械学習フレームワーク (CPU 版) | tensorflow==2.15.0.post1 | README.md |
| Python3x-PyMongo4x | Python 3.10, Custom.Debian10 | オープンソースの科学計算ライブラリ | PyMongo==4.6.1 | README.md |
| Python3x-Pandas2x | Python 3.9, Custom.Debian10 | NumPy をベースにしたオープンソースのデータ分析・処理ツール | pandas==2.2.1 | README.md |
| Python310-PyTorch2x | Python 3.10, Custom.Debian10 | オープンソースの機械学習フレームワーク (CPU 版) | torch==2.2.1+cpu | README.md |
| Python39-Pandas1x | Python 3.9, Custom, Custom.Debian10 | NumPy をベースにしたオープンソースのデータ分析・処理ツール | pandas==1.4.3 | README.md |
| Python39-SciPy1x | Python 3.9, Custom, Custom.Debian10 | オープンソースの科学計算ライブラリ | scipy==1.9.0, numpy==1.23.2 | README.md |
| Python36-SciPy1x | Python 3.6, Custom | オープンソースの科学計算ライブラリ | scipy-1.5.4, numpy-1.19.5 | README.md |
| Python39-PyTorch1x | Python 3.9, Custom, Custom.Debian10 | オープンソースの機械学習フレームワーク (CPU 版) | torch==1.12.1+cpu, torchaudio==0.12.1+cpu, torchvision==0.13.1+cpu | README.md |
| Python36-PyTorch1x | Python 3.6, Custom | オープンソースの機械学習フレームワーク (CPU 版) | 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 | Python ベースの軽量 Web フレームワーク | flask-v2.2.2 | README.md |
| Nodejs-Puppeteer17x | Node.js 16, Node.js 14, Custom, Custom.Debian10 | ヘッドレス Chrome ツール | puppeteer-v17.1.0 | README.md |
| Nodejs-Puppeteer10x | Node.js 14, Node.js 12, Node.js 10, Custom | ヘッドレス Chrome ツール | puppeteer-v10.2.0 | README.md |
| Nodejs-Puppeteer19x | Custom.Debian10 | ヘッドレス Chrome ツール | puppeteer-v19.8.5 | README.md |
| Python310-Opencv4x | Python 3.10, Custom.Debian10 | コンピュータビジョン向けのクロスプラットフォームライブラリ | opencv_python-4.7.0.68 | README.md |
| Python38-Playwright | Custom.Debian10 | Web ページ自動化ツール | playwright==1.31.1 | README.md |
| Poppler22x-Pdf2image | Python 3.10 | PDF ドキュメントをレンダリングするためのライブラリ | 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 | 軽量なインプロセスリレーショナルデータベース | 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 | 音声と映像の録画、変換、ストリーミングを行うためのオープンソースツールキット | 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 | 開発者向けに堅牢なツールセットを提供するオープンソースのサーバーレスプラットフォーム | 2.1.14 | README.md |
Web フレームワーク
| パブリックレイヤー | 互換性のあるランタイム | コアライブラリのバージョン | リファレンス |
|---|---|---|---|
| Python3-Flask2x | Python 3.9, Python 3.10, Custom, Custom.Debian10 | flask-2.2.2 | README.md |
Alibaba Cloud SDK
| パブリックレイヤー | 互換性のあるランタイム | 説明 | リファレンス |
|---|---|---|---|
| Python310-Aliyun-SDK | Python 3.10, Custom.Debian10 | Python 3.10 用の一般的な Alibaba Cloud SDK | README.md |
| Python39-Aliyun-SDK | Python 3.9, Custom | Python 3.9 用の一般的な Alibaba Cloud SDK | README.md |
| Python36-Aliyun-SDK | Python 3.6, Custom | Python 3.6 用の一般的な Alibaba Cloud SDK | README.md |
| Nodejs-Aliyun-SDK | Node.js 20, Node.js 18, Node.js 16, Node.js 14, Custom, Custom.Debian10 | 一般的な Alibaba Cloud SDK (Node.js 20、Node.js 18、Node.js 16、および Node.js 14) | README.md |
| Aliyun-DataX | Python 3.6, Python 3.9, Custom, Custom.Debian10 | Alibaba Cloud DataWorks データ統合のオープンソース版 | README.md |
レイヤーの仕組み
1 つの関数は、カスタムレイヤーとパブリックレイヤーを合わせて最大 5 つのレイヤーをサポートします。複数のレイヤーが設定されている場合、Function Compute はその内容を設定とは逆の順序で /opt ディレクトリにマージします。2 つのレイヤーに同じ名前のファイルが含まれている場合、最初に設定されたレイヤーのファイルが、後から設定されたレイヤーのファイルよりも優先されます。
コンソールでのパブリックレイヤーの追加
前提条件
開始する前に、以下を確認してください。
Function Compute の関数。作成方法については、「関数の作成」をご参照ください。
レイヤーの追加
Function Compute コンソールにログインします。左側のナビゲーションウィンドウで、 [関数] をクリックします。
上部のナビゲーションバーでリージョンを選択します。 [関数] ページで、設定する関数の名前をクリックします。
関数詳細ページで、 [設定] タブをクリックします。
左側のナビゲーションツリーで [レイヤー] をクリックし、次に [変更] をクリックします。
[レイヤー] パネルで [+ レイヤーの追加] をクリックし、 [公式共通レイヤーの追加] を選択します。 [公式共通レイヤー] ドロップダウンリストからレイヤーを、 [レイヤーバージョン] ドロップダウンリストからバージョンを選択し、 [デプロイ] をクリックします。
Serverless Devs を使用したパブリックレイヤーの追加
前提条件
開始する前に、以下を確認してください。
Serverless Devs がインストールされ、Docker が設定済みである必要があります。詳細については、「クイックスタート」をご参照ください。
ご利用の認証情報で Serverless Devs が設定されていること。詳細については、「Serverless Devs の設定」をご参照ください。
レイヤーの追加
次のコマンドを実行して、リージョン内の公式パブリックレイヤーをリスト表示します。
s cli fc layer list --official --region cn-hangzhou出力には、利用可能なレイヤーとその ARN がリスト表示されます。使用したいレイヤーの ARN をコピーします。
- 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.debian10出力の主要なフィールド:
フィールド 説明 layerNameレイヤーの名前 versionレイヤーバージョン arnレイヤーバージョンにアタッチする際に使用される ARN aclアクセス制御: 0= 非公開、1= パブリックdescriptionレイヤーの簡単な説明 compatibleRuntimeこのレイヤーがサポートするランタイム プロジェクトディレクトリに
s.yamlファイルを作成し、レイヤーの ARN をlayersフィールドに追加します。edition: 3.0.0 name: hello-world-app access: "default" vars: # グローバル変数 region: "cn-hangzhou" resources: hello_world: component: fc3 # コンポーネント名 actions: # カスタム実行ロジック 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: # 関数にアタッチされたレイヤーの ARN - acs:fc:cn-hangzhou:official:layers/Python39-Aliyun-SDK/versions/3プロジェクトディレクトリに
codeディレクトリを作成し、その中に関数コードを配置します。次のコマンドを実行して、レイヤーが設定された関数をデプロイします。
s deploy
次のステップ
CreateFunction および UpdateFunction API オペレーションを使用して、プログラムでレイヤーを管理します。
レイヤーを設定する際に
xxx is not supported by layerというエラーが表示された場合は、「関数にレイヤーを設定する際に「xxx is not supported by layer」と表示された場合の対処法」をご参照ください。