An OpenResty Edge Lua extension is a snippet of custom Lua code that Edge runs automatically when a built-in gateway event fires — for example, when a gateway server goes abnormally offline. You create, edit, and bind these extensions entirely from Edge’s web console under Global Config → Global Lua Extensions, choosing an event type as the trigger. This turns Edge into an event-driven automation platform: instead of polling or writing external glue code, you attach Lua logic directly to gateway lifecycle events.

This tutorial walks through building an event-driven Lua extension that reacts to the Gateway Server Abnormal Offline event and removes the dead node from GoDaddy DNS the moment a gateway server drops — so DNS stops resolving traffic to an offline node, with no manual intervention. For invoking reusable Lua from page rules instead of events, see the companion feature Global Lua Modules; for a webhook-based take on the same event-driven pattern, see Event-Driven Operations with OpenResty Edge Webhook.

How to create an OpenResty Edge Lua extension bound to a gateway event

OpenResty Edge provides powerful Lua extensions to automatically respond to offline events from the gateway server.

OpenResty Edge Lua extensions overview in the web console

Let’s switch to the web console of OpenResty Edge. This is our sample deployment of the console. Every user would have their own deployment.

Logging in to the OpenResty Edge web console sample deployment

Go to the “Global Config” page.

Navigating to the Global Config page in OpenResty Edge

Click on “Global Lua Extensions”.

Opening Global Lua Extensions under Global Config

Let’s create a new Lua Extension.

Clicking to create a new OpenResty Edge Lua extension

Create an extension to prevent GoDaddy from resolving a domain name to an already offline node.

New Lua extension form to remove an offline node from GoDaddy DNS

Here we enter the name as “remove_node_from_godaddy_if_node_is_offline”.

Naming the Lua extension remove_node_from_godaddy_if_node_is_offline

Lua extension configuration fields in OpenResty Edge

Select “By event”.

Selecting By event as the Lua extension trigger type

OpenResty’s Edge supports several kinds of built-in events.

Built-in gateway event types available for OpenResty Edge Lua extensions

Here, we select the type “Gateway Server Abnormal Offline”. This means that if the server is offline, the Lua Extension will be triggered.

Choosing the Gateway Server Abnormal Offline event as the trigger

If you are used to using Vim, you can enable Vim mode to edit code.

Enabling Vim mode in the OpenResty Edge Lua code editor

When the event occurs, it will pass trigger_event to Lua Extension.

Lua extension receiving the trigger_event data when the event fires

Send a request to the manager service, which could remove the node from GoDaddy when it’s offline.

Lua code sending a request to the manager service to remove the offline node

When the response content meets the conditions, use Lua’s cjson module to decode it and assign the result to the body variable.

Decoding the response with Lua cjson and assigning it to the body variable

If body exists and body.status equals 0, then output the successful message.

Checking body.status equals 0 and logging the success message in Lua

Click to create it!

Clicking Create to save the OpenResty Edge Lua extension

How to trigger and verify the Lua extension by taking a gateway server offline

After creating, the new Lua Extension will work automatically. Let’s test it with an offline gateway server.

Preparing to test the Lua extension with an offline gateway server

Go to Gateway Clusters’s page.

Opening the Gateway Clusters page in OpenResty Edge

This is the gateway cluster we are going to use.

The gateway cluster used for the Lua extension offline test

It’s online now.

Gateway server showing an online status before the test

Use the systemctl command on the terminal to stop the service.

Stopping the gateway service with systemctl on the terminal

Refresh the list.

Refreshing the gateway server list in OpenResty Edge

The server is offline now.

Gateway server now showing an offline status

Go back to “Global Config”.

Returning to the Global Config page in OpenResty Edge

Enter “Global Lua Extensions”.

Reopening Global Lua Extensions to check execution history

Check the history of execution.

Viewing the execution history of the Lua extension

As shown, the extension has been triggered and executed.

Execution history confirming the Lua extension was triggered and ran

The node has been removed from GoDaddy successfully.

GoDaddy DNS confirming the offline node was removed successfully

Frequently asked questions

What is a Lua extension in OpenResty Edge?

A Lua extension is a block of custom Lua code that OpenResty Edge runs automatically in response to a built-in gateway event. You write and manage it from the web console under Global Config → Global Lua Extensions, so you can add event-driven automation without touching the underlying gateway configuration files.

What events can trigger a Lua extension?

When you create an extension, you choose “By event” as its trigger. OpenResty Edge supports several kinds of built-in events; in this tutorial we use “Gateway Server Abnormal Offline”, which fires the extension whenever a gateway server goes offline.

Do I need to reload or restart the gateway after creating a Lua extension?

No. Lua extensions run on the Edge Admin (the management side), not on the gateway nodes (Edge Nodes), so there is no gateway to reload or restart. After you click Create, the new Lua extension works automatically — there is no extra activation step. The next time the bound event fires, the Edge Admin runs your Lua code.

What data does the extension receive when the event fires?

When the event occurs, OpenResty Edge passes a trigger_event value to the Lua extension, so your code knows which server or context triggered it and can act accordingly — for example, identifying the offline node to remove.

Can a Lua extension call an external service like a DNS provider?

Yes. In this example the extension sends a request to the manager service to remove the offline node from GoDaddy, then uses Lua’s cjson module to decode the response and checks whether body.status equals 0 before logging success. The same pattern works for any HTTP API.

How do I confirm a Lua extension actually ran?

Go back to Global Config → Global Lua Extensions and check the execution history. It shows whether the extension was triggered and executed — in this tutorial, confirming that the offline node was removed from GoDaddy DNS.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.