40
loading...
This website collects cookies to deliver better user experience
func init
host.json
local.settings.json
func new
index.js
function.json
func start
az version
az login
az account set
az group create
az storage account create
az functionapp create
func azure functionapp publish
brew tap azure/functions
brew install azure-functions-core-tools@3
host.json
, local.settings.json
, and subfolders with the code for individual functions.func init ajcwebdev-azure \
--worker-runtime javascript
Writing package.json
Writing .gitignore
Writing host.json
Writing local.settings.json
Writing /Users/ajcwebdev/ajcwebdev-azure/.vscode/extensions.json
cd ajcwebdev-azure
host.json
metadata file contains global configuration options that affect all functions for a function app.{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
local.settings.json
file stores app settings, connection strings, and settings used by local development tools.{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": ""
}
}
func new \
--template "Http Trigger" \
--name HttpTrigger
Select a number for template: Http Trigger
Function name: [HttpTrigger]
Writing
/Users/ajcwebdev/ajcwebdev-azure/HttpTrigger/index.js
Writing
/Users/ajcwebdev/ajcwebdev-azure/HttpTrigger/function.json
The function "HttpTrigger" was created successfully
from the "Http Trigger" template.
func new
to see the list of available templates and enter 10
to select HTTP trigger
.// index.js
module.exports = async function (context, req) {
context.log('You did it!')
const name = (req.query.name || (req.body && req.body.name))
const responseMessage = name
? "Hello, " + name + ". It worked!"
: "It worked! Pass a name for a personalized response."
context.res = {
status: 200,
body: responseMessage
}
}
function.json
we set req
and res
to the direction
in
and out
. Requests can be get
or post
.{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
func start
Core Tools Version: 3.0.3477
Commit hash: 5fbb9a76fc00e4168f2cc90d6ff0afe5373afc6d (64-bit)
Function Runtime Version: 3.0.15584.0
Functions:
HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger
For detailed output, run func with --verbose flag.
Executing 'Functions.HttpTrigger'
(
Reason='This function was programmatically called via the host APIs.',
Id=82dff9f9-6973-4275-8cd9-ff95524706b1
)
You did it!
Executed 'Functions.HttpTrigger'
(
Succeeded,
Id=82dff9f9-6973-4275-8cd9-ff95524706b1,
Duration=301ms
)
curl --get http://localhost:7071/api/HttpTrigger
curl --request POST http://localhost:7071/api/HttpTrigger \
--data '{"name":"ajcwebdev"}'
brew install azure-cli
az version
{
"azure-cli": "2.27.2",
"azure-cli-core": "2.27.2",
"azure-cli-telemetry": "1.0.6",
"extensions": {}
}
az login
.az login
az login --tenant TENANT_ID
to explicitly login to a tenant. You can find your tenant ID on the Azure Active Directory portal.az account set \
--subscription ajcwebdev-subscription
az group create command
creates a resource group. Create a resource group named ajcwebdev-rg
in the westus
region.az group create \
--name ajcwebdev-rg \
--location westus
{
"id": "/subscriptions/427c04b8-2468-4e47-9537-129b86bc7d3e/resourceGroups/ajcwebdev-rg",
"location": "westus",
"managedBy": null,
"name": "ajcwebdev-rg",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null,
"type": "Microsoft.Resources/resourceGroups"
}
az storage account create
command creates the storage account.az storage account create \
--name ajcwebdevstorage \
--location westus \
--resource-group ajcwebdev-rg \
--sku Standard_LRS
Standard_LRS
creates a general-purpose storage account in your resource group and region.az functionapp create
command creates the function app in Azure.az functionapp create \
--resource-group ajcwebdev-rg \
--consumption-plan-location westus \
--runtime node \
--runtime-version 12 \
--functions-version 3 \
--name ajcwebdev-function-app \
--storage-account ajcwebdevstorage
ajcwebdev-rg
for the resource group, ajcwebdevstorage
for the storage account, and ajcwebdev-function-app
for the name of the function app.func azure functionapp publish
command deploys your local functions project to Azure.func azure functionapp publish ajcwebdev-function-app
Getting site publishing info...
Creating archive for current directory...
Uploading 1.63 KB
Upload completed successfully.
Deployment completed successfully.
Syncing triggers...
Functions in ajcwebdev-function-app:
HttpTrigger - [httpTrigger]
Invoke url: https://ajcwebdev-function-app.azurewebsites.net/api/httptrigger?code=qFdxLBSxkswsQ/NZIeooMTlC4WS9awDgaGZi/OJPqgUzcKQYFYIwJA==
&name=person
.