3.0 KiB
Read this on the main serverless docs site
Quickstart
This guide is designed to help you get started as quick as possible.
1. Set up boilerplate
To setup the boilerplate, follow these instructions:
-
Install the boilerplate
serverless create -t azure-nodejs --path <my-app> -
Install the dependencies
cd <my-app> npm install
2. Set up credentials
We'll set up an Azure Subscription and our service principal. You can learn more in the credentials doc.
-
Set up an Azure Subscription
Sign up for a free account @ https://azure.com.
Azure comes with a free trial that includes $200 of free credit.
-
. Get the Azure CLI
npm i -g azure-cli -
Login to Azure
azure loginThis will give you a code and prompt you to visit aka.ms/devicelogin. Provide the code and then login with your Azure identity (this may happen automatically if you're already logged in). You'll then be able to access your account via the CLI.
-
Get your subcription and tenant id
azure account showSave the subcription and tenant id for later
-
Create a service principal for a given
<name>and<password>azure ad sp create -n <name> -p <password>This should return an object which has the
servicePrincipalNamesproperty on it. Save one of the names in the array and the password you provided for later. If you need to look up your service principal later, you can useazure ad sp -c <name>where<name>is the name provided originally. Note that the<name>you provided is not the name you'll provide later, it is a name in theservicePrincipalNamesarray. -
Set up environment variables
You need to set up environment variables for your subscription id, tenant id, service principal name, and password.
# bash export azureSubId='<subscriptionId>' export azureServicePrincipalTenantId='<tenantId>' export azureServicePrincipalClientId='<servicePrincipalName>' export azureServicePrincipalPassword='<password>'# PowerShell $env:azureSubId='<subscriptionId>' $env:azureServicePrincipalTenantId='<tenantId>' $env:azureServicePrincipalClientId='<servicePrincipalName>' $env:azureServicePrincipalPassword='<password>'
3. Deploy to Azure
Run the deploy command
serverless deploy
4. Test
Run the invoke command
serverless invoke -f hello