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?

API Management / Websocket - Azure - Memo

Last updated at Posted at 2023-08-19

概要

(自分用メモ)
AzureのAPI Managementを試す
APIM(API Management)はAzureの各種リソースのエンドポイント(HTTPサービス)のセキュリティをまとめて引き受ける。認証の検証等。

総目次
目次: Azure Development

前提

Azure portalサイトでお試し

API Managementリソース作成

Homeリソースの作成API Management作成

  • リソース名=エンドポイント(URL)のホスト名に含まれる。Azure全体でユニーク。例:apim230707
  • 価格レベル=Consumption(従量制)を指定。

作成
デプロイには多少の時間が必要。

FunctionAppでデプロイしたWebAPIを収容

概要作業の開始APIHTTP

  • Web service URL=Functionsで生成したURL
  • API URL suffixはとりあえず空にする
    Create

FrontendAdd Operation ➔ 例:URL=Get,/

  • Subscription required=unchecked (本来ダメ、お試しのみ)

テスト

SettingsBase URLで取得したURL(例:https://apim230101.azure-api.net)

以前作ったFunctionなら、パラメタ?name=Shokkaaをつけて
https://apim230101.azure-api.net?name=Shokkaa
をブラウザでアクセス。
Hello, Shokkaa. This HTTP triggered function executed successfully.
みたいに帰ってくれば成功。
APIMは何もしない設定なので、直接Functionsを呼び出すのと(URLを除いて)まったく同じ。

[TODO]認証

[TODO]

CLI操作

下記リソース作成と、設定をCLIで実行。
リソースグループ、Function App、APIインスタンス、APIM上のAPIセット、APIに対する操作

リソース名など設定とAzureへのログイン
RESGR=r1003
LOCATION=westus
FUNCAPP=app1003
APIM=${RESGR}apim

EMAIL=myid@my.domain

az login --use-device-code
Azure上にリソースグループ・Function・APIMリソース作成
az group create -n $RESGR --location $LOCATION
az storage account create -n s$FUNCAPP -g $RESGR -l $LOCATION 
az functionapp create -n $FUNCAPP -c $LOCATION -g $RESGR --storage-account s$FUNCAPP --os-type Linux --functions-version 4 --runtime node --runtime-version 18
az apim create --name $APIM -g $RESGR --publisher-name 'Shokkaa' --sku-name 'Developer' --publisher-email $EMAIL
# WebSocketはDeveloper(開発者)以上のプランが必要

FUNCURL=https://$FUNCAPP.azurewebsites.net/api/frev?param=
az apim api create --service-name $APIM -g $RESGR --api-id RevProxy --path '/' --display-name 'RevProxy'  --service-url $FUNCURL
az apim api operation create --service-name $APIM -g $RESGR --api-id RevProxy --url-template '/{param1}' --method 'GET' --display-name 'Get' --description 'Descrition' --template-parameters name=param1 description='Descrition' type=string
Azure上にWebPubSubリソース作成・PubSubにHub作成
PUBSUB=${RESGR}ps
HUB=hub1
az webpubsub create --name $PUBSUB -g $RESGR --sku 'Free_F1' --location $LOCATION
az webpubsub hub create --name $PUBSUB --hub-name $HUB -g $RESGR

# 確認
az webpubsub hub list --name $PUBSUB -g $RESGR
WebPubSub接続文字列取得
az webpubsub key show --name $PUBSUB -g $RESGR --query primaryConnectionString
# "Endpoint=https://r1003ps.webpubsub.azure.com;AccessKey=xxxxxxxx;Version=1.0;"

後片付け

リソース削除お忘れなく。

az group delete --name $RESGR
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?