LoginSignup
2
1

More than 1 year has passed since last update.

【ポチポチだけ!!】VSCode+DockerでAzure Functionsの開発環境構築

Posted at

Azure Functionsの開発環境

今回はVSCode+WSL+DockerAzure Functionsの開発環境を構築するよ
ボタンポチポチで作れちゃうのでめちゃ楽です

さっそく構築

まずはVSCodeを開き「拡張機能」から「Azure Functions」をインストールします

プロジェクトの作成

Azureロゴのアイコンを押してからFunctionsのボタンを押しましょう↓
6-1.png
画面上にタブが出てくるので「Python」を選択↓
6-2.png
pythonを選択すると仮想環境が自動で作られますが、今回はDev Containerを使うのでSkipを押しましょう
6-3.png
Functionsの関数を作るように言われるので、とりあえず「HttpTrigger」を選んでおきましょう

Dev Containerの作成

「ctrl + shift + p」を押したらコマンドパレットが表示されるので「Reopen in Container」を押しましょう
テンプレートがたくさん出てきます
「Show All Definitions...」という項目を押しましょう↓
6-4.png
Functions + Python用のテンプレートを選びます↓
6-5.png
ビルドが始まったらOKです!

ファイル構成

最終的に↓こんな感じのファイル構成になると思います(.git配下は省略)

test-functions
├── .devcontainer
│   ├── Dockerfile
│   └── devcontainer.json
├── .funcignore
├── .git/
├── .gitignore
├── .npmignore
├── .vscode
│   ├── extensions.json
│   ├── launch.json
│   ├── settings.json
│   └── tasks.json
├── HttpTrigger1
│   ├── __init__.py
│   ├── function.json
│   └── sample.dat
├── host.json
├── local.settings.json
└── requirements.txt

ローカル実行するよ

VSCode内のターミナルで「func start」を入力するだけで動くよ↓
6-6.png
ブラウザでアクセスしたらレスポンス来た!完成!おわり!
6-7.png

デプロイについて

Azureクラウド上のデプロイする場合は雲アイコンからできます(Azureログイン必須)↓
6-8.png
pipで入れたパッケージ等はpip freezeでrequirements.txtに記載しておけばデプロイ時に勝手にインストールしてくれます

最後に

Microsoftのドキュメントって読みにくいよね
いいね、ストックしていただけるとやる気が出ます🔥🙏

2
1
0

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
2
1