LoginSignup
2
2

More than 3 years have passed since last update.

Azure Functions をローカルで実行する

Last updated at Posted at 2021-03-31

Azure Functions をローカルで実行する

Azure Functionsを活用したアプリを作りたいなと思いつつも、いきなり使うのは無料枠があるとはいえちょっと不安なので、ローカルで実行環境を作り、お試しをしてみました。

↓↓参考にした公式ドキュメント

0. 環境

  • Windows10
  • npmインストール済み

1. Azure Function Core Tools のインストール

https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2
ここから自身の環境に合ったものをインストールします。
僕の場合はWindows用のインストーラをダウンロードして、指示通りにインストールしました。

2. ローカルでFunctionsプロジェクトの作成

funcコマンドが使えるようになっていると思うのでPowerShellなどで

func init MyFunctionProject

のようにコマンドを実行します。すると

Select a worker runtime:
dotnet
node
python 
powershell

のように選択肢を出されるのて欲しいランタイムを上下矢印キーで選んでEnterで決定します。
僕はnodeを選択しました。

3. Functionの作成

func initで作成したディレクトリに移動し、

func new

を実行します。

Select a language: Select a template:
Blob trigger
Cosmos DB trigger
Event Grid trigger
HTTP trigger
Queue trigger
SendGrid
Service Bus Queue trigger
Service Bus Topic trigger
Timer trigger

すると、func initの時と同様にtemplateの種類を聞かれるので好きなものを選びます。
僕はHTTP triggerを選択しました。
選択すると自動でテンプレートを作成してくれます。

4. ローカルでFunctionを実行

準備が整ったので早速実行していきます。
実行するコマンドは言語ごとに違うようなので、下記にまとめます。

C#

func start --build

Java

mvn clean package 
mvn azure-functions:run

JavaScript

func start

Python

func start

TypeScript

npm install
npm start     

これでローカルで実行することができました!!

5. まとめ

無事ローカルで試すことができたので、本格的にアプリ開発で活用したいと思います!

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