项目作者: honeymustard

项目描述 :
Azure Functions v3 sample project with DI-container and Github action deploy
高级语言: C#
项目地址: git://github.com/honeymustard/azure-functions-v3.git
创建时间: 2020-10-30T21:29:36Z
项目社区:https://github.com/honeymustard/azure-functions-v3

开源协议:MIT License

下载


Azure Functions v3

A sample Azure Functions 3.0 project with dependency injection, github action deploy routine, ready for local development.

Notes

  • Ignore the version 2.0 in host.json, it is not related to the runtime version
  • Timeout limit and other settings can be specified in host.json
  • Create as many folders and functions as you want in the Functions folder
  • New functions will appear in Function app after a deploy

How to run Azure functions locally

Azure Functions will run locally like they run in Azure, if you want to start a timer on demand you can trigger it with a script or use Postman to send requests. Azure blob storage credentials can be added to local.settings.json if you don’t like the additional step of starting Azurite manually.

  1. # Prerequisites
  2. npm i -g azure-functions-core-tools@3 --unsafe-perm true
  3. npm i -g azurite
  4. # Build the project
  5. dotnet build
  6. # Run the blob storage emulator
  7. azurite-blob
  8. # Start function host with a single active function
  9. func start --functions HorseTimer
  10. # While function host is running, you can trigger functions with a POST request
  11. http://localhost:7071/admin/functions/HorseTimer

Use the Dependency Injection container

This works just like it does in ASP.NET Core applications

Deploy functions to Azure with Github Actions

  • Create an Azure blob storage account in Azure Portal
  • Create an App setting named AzureWebJobsStorage with blob account connection string
  • Download publish settings from Azure Function App in Azure Portal
  • Create a Github secret named AZURE_FUNCTIONAPP_PUBLISH_PROFILE, paste publish settings
  • Insert application name in Github action workflow Azure.yml
  • Deploy to Azure by pushing a commit to main branch