Make sure serverless
is installed. See installation guide.
Once installed the Serverless CLI can be called with serverless
or the shorthand sls
command.
$ sls
Commands
* You can run commands with "serverless" or the shortcut "sls"
* Pass "--verbose" to this command to get in-depth plugin info
* Pass "--no-color" to disable CLI colors
* Pass "--help" after any <command> for contextual help
sls create --template azure-nodejs --path $(whoami)-sample-app
Using the create
command we can specify one of the available templates. For this example we use azure-nodejs with the --template
or shorthand -t
flag.
The --path
or shorthand -p
is the location to be created with the template service files.
Azure plugin use a combination of:
to generate resource names. Since resource name have to be unique in Azure, adding $(whoami)
will append your username to
the service name, thus creating a unique name.
Change directories into the new folder created in previous step.
Run
npm install
You can skip this section if you do not want to test your functions locally before deploy.
sls offline
sls invoke local -f hello -d '{"name": "Azure"}'
In your terminal window you should see the following response
$Serverless: URL for invocation: http://localhost:7071/api/hello?name%3DAzure
$Serverless: Invoking function hello with GET request
$Serverless: "Hello Azure"
sls deploy
Invoke deployed function with command invoke
and --function
or shorthand -f
.
sls invoke -f hello -d '{"name": "Azure"}'
In your terminal window you should see the response from azure
$Serverless: Logging into Azure
$Serverless: Using subscription ID: A356AC8C-E310-44F4-BF85-C7F29044AF99
$Serverless: URL for invocation: http://{baseURL}.azurewebsites.net/api/hello?name%3DAzure
$Serverless: Invoking function hello with GET request
$Serverless: "Hello Azure"
Congrats you have deployed and ran your Hello World function!
Product