LoginSignup
3

More than 3 years have passed since last update.

VS Code+Azure Functions+Python環境構築手順

Posted at

前提条件

※ローカルで起動&動作確認までとしており、Azureへのデプロイまでは行わないのでAzureのアカウントは不要

環境構築

Python(3.7.x)

以下から3.7.4の64bit版をダウンロードしてインストール
プロセスの終了時にDisable Path length limit(パスの長さの制限を無効にする)を実施
※32bit版だとローカルデバッグ時に異常が発生したので64bit版にする
https://www.python.org/downloads/
PythonInstall.png

VS Codeプラグインのインストール

  • Python
    image.png

  • Azure Functions
    vscode_azure_functions.png
    インストール完了すると左のメニューにAzureのボタンが増え選択すると「FUNCTIONS」表示が増える
    vscode_azure_functions2.png

Azure Functions Core Tools

VS Code上で「F1」押下⇒「Azure Functions: Install or Update Azure Functions Core Tools」と入力してEnter
※参照
https://docs.microsoft.com/ja-jp/azure/javascript/tutorial-vscode-serverless-node-01#install-the-azure-functions-core-tools
vscode_core_tools1.png
「Azure Functions v3」を選択してEnter
⇒インストール完了するまで待つ
vscode_core_tools2.png
ターミナルからfuncと叩いてAzure Functionsマークetcが表示がされること
vscode_func.png

Azure Functionsプロジェクト(Python)の作成

以下を参考にAzure Functionsのプロジェクトを作成する
https://docs.microsoft.com/ja-jp/azure/python/tutorial-vs-code-serverless-python-02

  1. フォルダを選択 image.png
  2. 言語(Python)を選択 image.png
  3. Pythonのバージョン(3.7.4)を選択 image.png
  4. トリガーを選択(APIにするのでHTTP triggerを選択) image.png
  5. 関数名を設定(関数名=エンドポイントになる) image.png
  6. 承認レベル(Anonymous)を選択 image.png
  7. プロジェクトの作成が完了すると1.で選択したフォルダにプロジェクトが作成され__init__.pyが表示される image.png

起動&動作確認

メニューの「デバッグ」⇒「デバッグの開始」などからFunctionsを起動
起動が完了するとURLが表示されるのでCtrl+クリックでブラウザからアクセス
image.png

以下のように表示されAPIが実行されていることが確認できる
※クエリストリングorリクエストボディにnameパラメータを設定することでHello {name}!と表示されるようにデフォルトはなっている
image.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3