0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

.NET 6.0 の Azure Functions を App Service で動かしてみた

Posted at

背景と目的

Azure で Function as a Service (FaaS) といえば、Azure Functions です。従量課金プランで使用することが多いのですが、今回は専用プラン (App Service プラン) で .NET 6 の Azure Functions を動作確認してみました。

前提条件

コマンドの実施環境は、Mac + Azure CLI + .NET 6.0 です。

bash
$ sw_vers
ProductName:    macOS
ProductVersion: 12.2.1
BuildVersion:   21D62

$ az version
{
  "azure-cli": "2.34.1",
  "azure-cli-core": "2.34.1",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

$ dotnet --version
6.0.200

Azure Functions Core Tools のインストール

https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-run-local?tabs=v4%2Cmacos%2Ccsharp%2Cportal%2Cbash#install-the-azure-functions-core-tools

bash
brew tap azure/functions

brew install azure-functions-core-tools@4

# 2.x または 3.x がインストールされているマシンでアップグレードする場合に実行します
brew link --overwrite azure-functions-core-tools@4

ローカル関数プロジェクトを作成する

https://docs.microsoft.com/ja-jp/azure/azure-functions/create-first-function-cli-csharp?tabs=azure-cli%2Cin-process#create-a-local-function-project

bash
func init LocalFunctionProj --dotnet

cd LocalFunctionProj

func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"

func start

# 別ターミナルで実行
curl "http://localhost:7071/api/HttpExample?name=Functions"

# 以下のような出力結果が表示されます
Hello, Functions. This HTTP triggered function executed successfully.

# func start を止めます
[Ctrl + C]

App Service を作成する

https://docs.microsoft.com/ja-jp/azure/azure-functions/create-first-function-cli-csharp?tabs=azure-cli%2Cin-process#create-supporting-azure-resources-for-your-function

bash
# 環境変数をセットします
region=japaneast
prefix=mnrfasrv

# リソースグループを作成します
az group create \
  --name ${prefix}-rg \
  --location $region

# ストレージアカウントを作成します
az storage account create \
  --name ${prefix}stor \
  --resource-group ${prefix}-rg \
  --sku Standard_LRS

# App Service プランを作成します
az appservice plan create \
  --name ${prefix}-plan \
  --resource-group ${prefix}-rg \
  --sku B1 \
  --is-linux

# Functions を作成します
az functionapp create \
  --name ${prefix}-fapp \
  --resource-group ${prefix}-rg \
  --storage-account ${prefix}stor \
  --plan ${prefix}-plan \
  --runtime dotnet \
  --functions-version 4

# Functions App を App Service にデプロイします
func azure functionapp publish ${prefix}-fapp

# 動作確認します
curl "https://${prefix}-fapp.azurewebsites.net/api/httpexample?name=Azure"

# 以下のような出力結果が表示されます
Hello, Azure. This HTTP triggered function executed successfully.

参考

bash
# ログストリーミングを表示します
func azure functionapp logstream ${prefix}-fapp

# リソースグループを削除します
az group delete \
  --name ${prefix}-rg \
  --yes

https://docs.microsoft.com/ja-jp/azure/azure-functions/dedicated-plan

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?