部署到 Azure Functions
本指南介绍了使用 Azure 函数 将基于 Node.js 的函数应用部署到 Azure 时如何避免常见问题。
¥This guide explains how to avoid common issues when deploying a Node.js-based function app to Azure using Azure Functions.
Azure Functions 是一个无服务器部署平台。你不需要维护基础设施来部署代码。对于 Azure Functions,基本构建块是 功能应用。函数应用在 Azure 中提供运行函数的执行上下文。它由 Azure 一起管理、部署和扩展的一项或多项单独功能组成。你可以将多个功能作为单个逻辑单元进行组织和集中管理。
¥Azure Functions is a serverless deployment platform. You do not need to maintain infrastructure to deploy your code. With Azure Functions, the fundamental building block is the function app. A function app provides an execution context in Azure in which your functions run. It is comprised of one or more individual functions that Azure manages, deploys, and scales together. You can organize and collectively manage multiple functions as a single logical unit.
先决条件
¥Prerequisites
-
使用 Prisma ORM 的现有函数应用项目
¥An existing function app project with Prisma ORM
要知道的事情
¥Things to know
虽然 Prisma ORM 可以很好地与 Azure 函数配合使用,但在部署应用之前需要注意一些事项。
¥While Prisma ORM works well with Azure functions, there are a few things to take note of before deploying your application.
定义多个二进制目标
¥Define multiple binary targets
部署函数应用时,Azure Functions 运行远程构建的操作系统与用于托管函数的操作系统不同。因此,我们建议在你的 Prisma 架构中指定以下 binaryTargets
选项:
¥When deploying a function app, the operating system that Azure functions runs a remote build is different from the one used to host your functions. Therefore, we recommend specifying the following binaryTargets
options in your Prisma schema:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-1.1.x"]
}
连接池
¥Connection pooling
通常,当你使用 FaaS(函数即服务)环境与数据库交互时,每次函数调用都会导致与数据库的新连接。对于持续运行的 Node.js 服务器来说,这不是问题。因此,池化数据库连接有利于获得更好的性能。要解决此问题,你可以使用 Prisma 加速。其他解决方案请参见 无服务器环境的连接管理指南。
¥Generally, when you use a FaaS (Function as a Service) environment to interact with a database, every function invocation can result in a new connection to the database. This is not a problem with a constantly running Node.js server. Therefore, it is beneficial to pool DB connections to get better performance. To solve this issue, you can use the Prisma Accelerate. For other solutions, see the connection management guide for serverless environments.
概括
¥Summary
要更深入地了解 Prisma Client 的 API,请探索函数处理程序并查看 Prisma 客户端 API 参考
¥For more insight into Prisma Client's API, explore the function handlers and check out the Prisma Client API Reference