Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adbertram/d5b0ec8ebe2a18d5b1f634fd41659046 to your computer and use it in GitHub Desktop.
Save adbertram/d5b0ec8ebe2a18d5b1f634fd41659046 to your computer and use it in GitHub Desktop.
###################################################
# This is an associated snippet on learning Azure Functions by Jeff Brown at:
# https://adamtheatuomator.com/azure-functions-tutorial
###################################################
# The function URL appends the function name with a question mark and a code. This code is the function key and
# authenticates to the function for execution. Without this key, you would not be able to trigger the function.
# This key provides security so not just anyone can start the function.
$functionKey = '' ## Fill this in from the Get function URL page
$functionAppName = 'ata-powershell-functions'
$loggerUrl = "https://$functionAppName.azurewebsites.net/api/LoggerFunction?code=$functionKey"
# Next, build the HTTP request body object using a PowerShell hash table. The HTTP request body contains two pieces
# of information to pass to the function: the severity of the log entry and the log message.
$requestBody = @{
Severity = 'INFO'
Message = 'This is my first Azure Function using an HTTP trigger.'
}
# Convert the PowerShell hash table into JSON using the ConvertTo-Json command and storing this to a new variable.
$requestBodyJson = ConvertTo-Json -InputObject $requestBody
# Finally, invoke an HTTP request. Use the POST method and specify the body and URL already saved to variables.
Invoke-RestMethod -Method Post -Body $requestBodyJson -Uri $loggerUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment