Azion Runtime
Run JavaScript functions on Azion Runtime with Web APIs, Node.js polyfills, and Azion APIs, and see how a request reaches your code.
A JavaScript runtime is the environment that executes code: it supplies the language engine, the global objects, and the APIs the code can call. In a serverless runtime, you write a handler that receives one request and returns a response. The platform starts the handler when a request arrives, so there is no server for you to provision or scale.
Azion Runtime is the JavaScript runtime of Functions. It runs your handler on Azion’s distributed infrastructure, close to the users who send the requests, and Azion provisions what the code needs to run. The code is built on Web standards and runs in strict mode. It calls Web APIs, a part of the Node.js APIs through polyfills, and Azion APIs for variables, request metadata, storage, and databases. Use Azion Runtime to put business logic in front of an application, build serverless applications, change responses as they stream, or store and query data from a function.
Get started Browse the Web APIsFunction structure
A function for Azion Runtime is a JavaScript module whose default export holds a fetch handler. The smallest complete function answers every request with the same text:
Deployed, the function returns this response:
export default { fetch }is the ES Modules shape, the one Azion recommends. Azion Runtime also runs the Service Worker pattern,addEventListener('fetch', …), and a deprecated default-export function.requestis a standardRequest. Itsmetadataproperty adds data about the client, such as the geolocation and the TLS protocol.envis an empty object in a deployed function. A function reads its variables withAzion.env.get()orprocess.env.ctxcarriesargs, the Args of the function instance, andwaitUntil(), which extends the execution until a promise settles.
Code written for the Web Request and Response objects, in a browser or in another standards-based runtime, follows the same model on Azion Runtime. For every parameter and handler shape, refer to Handlers.
Invocation path
Writing a function does not run it. Your code reaches Azion Runtime through a build, and a request reaches your code only when a rule on an application runs an instance of the function.
azion buildruns Azion Bundler, which bundles your code and resolves the Node.js APIs it calls with polyfills, at build time.azion deploypublishes the result as a function.- A function instance places the function on an application. Its
activefield stops the instance from running without deleting it. The application must have Functions turned on in the Modules section of its Main Settings. - A request arrives, and a Rules Engine rule whose criteria match runs its Run Function behavior, which names the instance.
- Azion Runtime runs the function in an isolate, a V8 execution context, in the data center that serves the request.
- The runtime calls the handler, and the handler returns a
Response. Work passed toctx.waitUntil()can finish after the handler returns. - Control returns to Rules Engine, which continues with the behaviors that follow.
For the request lifecycle, the bundler, and time inside a request, refer to How Azion Runtime works.
Capabilities and limits
A function on Azion Runtime calls standard APIs, a part of Node.js, and the APIs of the platform, inside an isolate with fixed ceilings:
- Language: JavaScript. Azion makes strict mode the default and required mode for every function, so some silent errors become thrown errors. For more information, refer to Strict mode and to the MDN strict mode reference.
- Web APIs: the runtime groups its Web APIs into network, encoding and decoding, Web Streams, Web standards, V8 primitives, Web Crypto, and EventTarget. Azion participates in WinterTC (TC55), the Ecma International committee that standardizes a minimum common API for server-side JavaScript runtimes. A function built only on those APIs ports to other runtimes that implement them. For every API, refer to Web APIs. Globals lists the names a function uses without an import.
- Node.js APIs: a function can import 68 Node.js modules, and each one resolves when the build bundles the function. A module that builds does not always work at run time: some are partially supported, and build-only modules are stubs whose calls return empty values or throw. For the status of each module, refer to Node.js APIs.
- Azion APIs: a function reads environment variables and secrets, the metadata of a request, and network lists. It stores data with the Object Storage API and the KV Store API, and queries a database with the SQL Database API. It also runs models with the AI Inference API, and uses the Cache API and WebSocket.
- Isolation: an isolate gives the code no access to the host operating system, no DNS resolution through native system calls, and no low-level TCP or UDP sockets. Each invocation runs inside the memory and CPU time ceilings on Functions limits.
- Invocation: Azion Runtime runs the code but does not decide when it runs. The rule and the function instance decide, as How Functions works describes.
- Interfaces: the Azion CLI runs a function locally with
azion dev, and builds and deploys it withazion buildandazion deploy.azion devemulates the runtime, and several APIs behave differently there. For the differences, refer to Local and deployed behavior. - Frameworks: projects built with web frameworks deploy through Azion Bundler. For the support of each framework, refer to Frameworks compatibility.
- Terms and help: the Glossary defines the terms of Azion Runtime, and Support guidelines lists the support and community channels.