Boilerplate project for a serverless API with automated OpenAPI specification on Azure Functions
This project is currently just me figuring out the best ways to do Serverless APIs in Azure with nice tooling.
- Local development with Azure Functions Core Tools
- Azure infra deployment with Terraform
- Azure Function App with Linux Node.js runtime
- Azure Database for PostgreSQL
- Azure Redis Cache
- Continuous deployment using ZIP deployment on Azure
- Automated OpenAPI specification
Requirements:
- Node.js v10+
- Azure Functions Core Tools
- Local PostgreSQL (docker-compose file included)
- Terraform
- Azure CLI
source .env.sample # Set up environment variables
npm install
# docker-compose up --detach # PostgreSQL listening at port 5432
# npm run migrate # Set up database schema with knex migrations
npm run dev # Core Tools Start: http://localhost:9000
Requirements:
In Azure Portal, gather or create the following items:
- Subscription
- ID
- Resource Group
- Name
- Storage Account
- Name
- Access Key
- Blob Storage Container
- Name
In your .env
file, fill the missing environment variables.
# .env
export PROJECT_NAME=<unique name for your project>
export ARM_SUBSCRIPTION_ID=<Subscription ID>
export ARM_RESOURCE_GROUP=<Resource Group Name>
export ARM_ACCESS_KEY=<Storage Account Access Key>
Then source the file to load the environment variables.
source .env
If you wish, you can configure the terraform remote backend to a blob storage container.
See terraform-backend.tf.sample
:
terraform {
backend "azurerm" {
storage_account_name = "<Storage Account Name>"
container_name = "<Blob Storage Container Name>"
key = "terraform.tfstate"
}
}
Init Terraform and deploy!
terraform init
terraform apply
npm run build
func azure functionapp publish $PROJECT_NAME-<stage> --zip