Migrating handler patterns in Functions
Learn how to migrate your Azion Functions from the legacy Service Worker pattern to the recommended ES Modules pattern, including fetch and firewall handlers.
Azion Functions supports two handler patterns: ES Modules (recommended) and Service Worker (legacy). This guide explains the differences between them and how to migrate your existing functions to the ES Modules pattern.
Supported patterns
ES Modules (recommended)
The ES Modules pattern is the recommended way to structure your functions on Azion. It provides a modern, clean syntax with native support in production and better performance.
Service Worker (legacy)
The Service Worker pattern is maintained for backward compatibility. If you’re using this pattern, Azion recommends migrating to ES Modules.
Handler parameters
fetch(request, env, ctx)
| Parameter | Type | Description |
|---|---|---|
request | Request | The incoming HTTP request object |
env | Object | Environment variables and bindings |
ctx | Object | Execution context. Use ctx.waitUntil(promise) to extend the function’s lifetime for async tasks |
firewall(request, env, ctx) — ES Modules
| Parameter | Type | Description |
|---|---|---|
request | Request | The incoming HTTP request object |
env | Object | Environment variables and bindings |
ctx | Object | Execution context. Call ctx.deny() to block the request immediately. If ctx.deny() is not called, the request continues to the fetch handler |
Firewall event — Service Worker
| Property | Description |
|---|---|
event.request | Access to the Request object |
event.deny() | Blocks the request immediately. If not called, the request continues to the fetch handler |
Migrating from Service Worker to ES Modules
Basic fetch handler
Before (Service Worker):
After (ES Modules):
Firewall handler
Before (Service Worker):
After (ES Modules):
Using waitUntil for async tasks
Advanced firewall with path-based rules
Unsupported patterns
The following patterns are not supported by Azion Functions. If your code uses any of them, migrate to the ES Modules pattern.
Troubleshooting
”Unsupported handler pattern detected”
This error appears when your code doesn’t follow any of the supported patterns. To resolve it, migrate to the ES Modules pattern:
Alternatively, use the Service Worker pattern as a temporary measure: