Serverless deployment is one of the latest trends in cloud technologies. It is a development model built for creating and running applications without need for server management. They are provisioned, maintained and scaled by a third-party cloud provider, while the developers just write and deploy the code.
Azure Function is a serverless solution that allows you to write less code, maintain less infrastructure and save on costs. Instead of worrying about deploying and maintaining servers, Azure provides all the up-to-date resources needed to keep your applications running.
Here is a list of everything you need to have before proceeding with deployment:
- Active Azure account
- Active Azure subscription
- Azure CLI version 2.4 or later
- Node and npm
-
Navigate to the root directory and run the following command to include the npm dependencies
npm install
NOTE: This is not necessary if the dependencies are already available in node_modules repository
-
Populate .env file with the required data by referring to the values from API-Extension-Setup
-
Run the following command
npm run zip-functionOnce the above command is successfully executed, it will create a zip file name as
ctExtension.zip. This file will be used for zip deployment. -
To deploy a service, run below commands in the root directory of extension
-
Run the below command and login with your Azure account credential.
az login -
Create Resource Group by entering below command.
az group create --name <Resource_Group_Name> --location <Location_Name>Resource_Group_Nameis the name of the resource group andLocation_Nameis the Azure region. -
Create Storage Account by entering below command. Provide
Resource_Group_NameandLocation_Nameused in above step.az storage account create --name <Globally_Unique_Storage_Account_Name> --location "<Location_Name>" --resource-group <Resource_Group_Name> -
Create a function app by entering below command. Use
Resource_Group_Name,Location_Name&Globally_Unique_Storage_Account_Namecreated in above steps.az functionapp create --resource-group <Resource_Group_Name> --consumption-plan-location <Location_Name> --runtime node --functions-version 4 --name <Globally_Unique_Function_App_Name> --storage-account <Globally_Unique_Storage_Account_Name> -
Deploy your zip file to the function app, by entering below command. Use
Resource_Group_NameandGlobally_Unique_Function_App_Namecreated in above commands.az functionapp deployment source config-zip -g <Resource_Group_Name> -n <Globally_Unique_Function_App_Name> --src ctExtension.zip
-
Your application is now available at https://<Globally_Unique_Function_App_Name>.azurewebsites.net
- In order to see the extension logs in Cloudwatch, console.log statement can be added inside the
logDatafunction in PaymentUtils.ts file for general logs, and inside thelogErrorfunction in ErrorHandler.ts file for Error logs. The logs can be found in your Azure Function, underMonitoring-->Log Stream
NOTE: Logs displayed here will not be stored permanently
- To add an environment variable, navigate to your Function app.
- Go to
Settings->Configuration, click onNew application settingand enter Name and Value of the environment value and enableDeployment slot setting. - Click on
OKandSavebutton. - You can edit your environment variable by following same path and click on the variable name and modify the value, click on
OKandSavebutton to save your changes.