Skip to content

Latest commit

 

History

History

azure-ts-serverless-http-trigger

Deploying Serverless Applications with Azure Functions

In this lab, you will deploy a Azure Function Apps with HTTP-triggered serverless functions. This is in TypeScript

Deployment

  1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step)

    az login
  2. Create a new stack:

    pulumi stack init dev
  3. Install dependencies

    npm install
  4. Configure the location to deploy the resources to. The Azure region to deploy to is pre-set to WestUS - but you can modify the region you would like to deploy to.

    pulumi config set azure-native:location eastus2

    pulumi config set allows us to pass in configuration values from the command line. Feel free to choose any Azure region that supports the services used in these labs (see this infographic for current list of available regions). A list of some of the regions:

    centralus,eastasia,southeastasia,eastus,eastus2,westus,westus2,northcentralus,southcentralus,
    westcentralus,northeurope,westeurope,japaneast,japanwest,brazilsouth,australiasoutheast,australiaeast,
    westindia,southindia,centralindia,canadacentral,canadaeast,uksouth,ukwest,koreacentral,koreasouth,
    francecentral,southafricanorth,uaenorth,australiacentral,switzerlandnorth,germanywestcentral,
    norwayeast,jioindiawest,australiacentral2

    The command updates and persists the value to the local Pulumi.dev.yaml file. You can view or edit this file at any time to effect the configuration of the current stack.

  5. Azure TypeScript Function Zip file

    The applications settings configure the app to run on Node.js v14 runtime and deploy the specified zip file to the Function App. The app will download the specified file, extract the code from it, discover the functions, and run them. We’ve prepared this zip file for you to get started faster, you can find its code here. The code contains a single HTTP-triggered Azure Function in the zip file.

  6. Run pulumi up to preview and select yes to deploy changes:

    pulumi up
     Previewing update (dev)
    
     View Live: https://app.pulumi.com/shaht/azure-ts-serveless-http-trigger/dev/previews/6c53075a-16f3-4b7b-a695-8b85dde7edc8
    
         Type                                     Name                                 Plan       
     +   pulumi:pulumi:Stack                      azure-ts-serveless-http-trigger-dev  create     
     +   ├─ azure-native:resources:ResourceGroup  resourcegroup_functions              create     
     +   ├─ azure-native:web:AppServicePlan       consumption-plan                     create     
     +   ├─ azure-native:storage:StorageAccount   storageaccount                       create     
     +   └─ azure-native:web:WebApp               functionapp                          create     
     
     Resources:
         + 5 to create
    
     Do you want to perform this update? yes
     Updating (dev)
    
     View Live: https://app.pulumi.com/shaht/azure-ts-serveless-http-trigger/dev/updates/4
    
         Type                                     Name                                 Status      
     +   pulumi:pulumi:Stack                      azure-ts-serveless-http-trigger-dev  created     
     +   ├─ azure-native:resources:ResourceGroup  resourcegroup_functions              created     
     +   ├─ azure-native:storage:StorageAccount   storageaccount                       created     
     +   ├─ azure-native:web:AppServicePlan       consumption-plan                     created     
     +   └─ azure-native:web:WebApp               functionapp                          created     
     
     Outputs:
         consumptionplan  : "consumption-plandc67323d"
         endpoint         : "https://functionapp1bc0168d.azurewebsites.net/api/hello"
         primaryStorageKey: "[secret]"
         resourcegroup    : "resourcegroup_functions7583fe98"
         storageaccount   : "storageaccount8d208154"
    
     Resources:
         + 5 created
    
     Duration: 1m4s
  7. Check the deployed function endpoints via pulumi stack output

    pulumi stack output endpoint

    Results

    https://functionapp1bc0168d.azurewebsites.net/api/hello

    You can now open the resulting endpoint in the browser or curl it:

    curl $(pulumi stack output endpoint)

    You've successfully deployed a Function App!

  8. Clean up - Destroy the Stack

    pulumi destoy -y
  9. Remove the stack

    pulumi stack rm dev