この記事の目的
Azure Functions を作成し、Azure Functions Core Tools
を利用してデプロイする手順を解説します。
👇これより先は下記内容を前提とします
Azure Functions Core Tools のインストール
Azure Functions Core Tools
をインストールします。
(参考)
Azure Functions Core Tools のインストール
ローカル関数の作成
func init
コマンドを実行して、LocalFunctionProj というフォルダーに関数プロジェクトを作成します。
func init LocalFunctionSampleProj --python -m V2
プロジェクトフォルダーに移動します。
cd LocalFunctionSampleProj
関数を作成します。
func new
下記のようにtemplateの選択プロンプトが表示されるので、ここではTimer Trigger
を選択します。
Use the up/down arrow keys to select a template:
Blob trigger
CosmosDB trigger
EventGrid trigger
EventHub trigger
HTTP trigger
Queue trigger
ServiceBus Queue trigger
ServiceBus Topic trigger
Timer Trigger
関数名を入力します。ここではtimer_trigger_func01
と入力します。
Use the up/down arrow keys
to select a template:Function Name: [timer_trigger] timer_trigger_func01
CRON式を入力します。ここではデフォルトのままにしますので、何も入力せずにEnterを入力します。
Schedule: [0 */5 * * * *]
関数が作成されます。
最終的に下記内容が出力されます。
Use the up/down arrow keys
to select a template:Function Name: [timer_trigger] timer_trigger_func01
Schedule: [0 */5 * * * *]
Appending to C:\****\local_projects\LocalFunctionSampleProj\function_app.py
The function "timer_trigger_func01" was created successfully
from the "Timer Trigger" template.
パッケージ依存関係をrequirements.txt
に定義します。
詳細は下記参照下さい。
Azure Functions の Python 開発者向けガイド
azure-functions
azure.identity==1.15.0
azure.mgmt.compute==30.3.0
azure.mgmt.network==25.1.0
azure.mgmt.resource==23.0.1
関数用の関連 Azure リソースを作成する
Azure ログインを実施し、サブスクリプションを設定します。
az login
az account set --subscription "*****-****-****-****-****"
リソースグループresource_group_for_python
に、ストレージアカウントsasample09
を作成します。
az storage account create^
--name sasample09^
--location japaneast^
--resource-group resource_group_for_python^
--sku Standard_LRS
リソースグループresource_group_for_python
に、関数アプリappsample09
を作成します。
Pythonバージョンは本記事記載時点の最新バージョン3.11
を指定します。
az functionapp create^
--resource-group resource_group_for_python^
--runtime python^
--runtime-version 3.11^
--functions-version 4^
--storage-account sasample09^
--os-type linux^
--consumption-plan-location japaneast^
--name appsample09
## Azure に関数プロジェクトをデプロイする
プロジェクトフォルダーに移動します。
```text
cd LocalFunctionSampleProj
Azure の関数アプリappsample09
に関数プロジェクトをデプロイします。
※ 関数アプリ作成直後にデプロイすると失敗します。数分程待ってから再度デプロイしてみて下さい。
func azure functionapp publish appsample09
下記のような内容が出力されればデプロイ成功です。
Generating summary of Oryx build
Deployment Log file does not exist in /tmp/oryx-build.log
The logfile at /tmp/oryx-build.log is empty. Unable to fetch the summary of build
Triggering recycle (preview mode disabled).
Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
Remote build succeeded!
👇関連記事
👇参考URL
- コマンド ラインから Azure に Python 関数を作成する
- Azure Functions Core Tools リファレンス
- az functionapp create
- az functionapp plan create
- Azure Functions の Python 開発者向けガイド
- requirements.txt を手動で作成する
[keywords]
AzureFunctions Python Core Tools deploy
Azure Functions でPython関数を作成してデプロイする
更新日:2023/11/09