2017-07-04 21 views

答えて

3

あなたはすでにあなたの表の記憶域に接続文字列を持っているAzureWebJobsStorageをという名前の関数Appのアプリの設定を持っていると仮定し、その後、あなたのPowerShellスクリプトでその値を取得するために、あなたは、以下を追加します

$connectionString = $env:AzureWebJobsStorage; 

ただし、行キーに基づいてテーブルストレージに書き込むだけであれば、Azure関数ですでにサポートされているテーブルストレージバインディングを活用できます。

testtableという名前のテーブルが既にテーブルストレージに作成されており、これを書き込む必要があるテーブルがあるとします。次に、HTTPトリガーの照会ストリングから行キーを読み取り、表ストレージに項目を書き込むサンプルのセットアップを示します。

function.json:

{ 
    "bindings": [ 
    { 
     "name": "req", 
     "type": "httpTrigger", 
     "direction": "in", 
     "authLevel": "anonymous" 
    }, 
    { 
     "type": "table", 
     "name": "outputTable", 
     "tableName": "testtable", 
     "connection": "AzureWebJobsStorage", 
     "direction": "out" 
    }, 
    { 
     "name": "res", 
     "type": "http", 
     "direction": "out" 
    } 
    ], 
    "disabled": false 
} 

run.ps1:ポストマンで

# POST method: $req 
$requestBody = Get-Content $req -Raw | ConvertFrom-Json 
$name = $requestBody.name 

# GET method: each querystring parameter is its own variable 
if ($req_query_name) 
{ 
    $name = $req_query_name 
} 

Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $name" 

Write-Output "Message entity: '$requestBody'" 
$entity = [PSObject]@{ 
    PartitionKey = $requestBody.role 
    RowKey = $req_query_rowkey 
    AccountId = $requestBody.id 
} 

$entity | ConvertTo-Json | Out-File -Encoding UTF8 $outputTable 

試験:

enter image description here

ログビュー:Azureストレージエクスプローラーで

2017-07-04T17:21:17.095 Function started (Id=775a36ce-9d71-454c-887c-05f08cfdb877) 
2017-07-04T17:21:17.314 Message entity: '@{name=Azure; role=admin; id=78910}' 
2017-07-04T17:21:17.314 Function completed (Success, Id=775a36ce-9d71-454c-887c-05f08cfdb877, Duration=222ms) 

表のエントリビュー:

enter image description here

+0

これは素晴らしいです、ありがとうございます。 PowerShellを使用してHTTPトリガーで '$ connectionString = $ env:AzureWebJobsStorage'を使用してテーブルストレージから読み込む方法に関する例はありますか? –

+1

優れた答え。マイクロソフトの開発者がここでこのような答えを書いていることはとても素晴らしいことです。 – briantist

+1

@DougFinke、私たちのTwitterでの会話では、自分のフォローアップの質問に対する答えを見つけたと思います。 –

関連する問題