---
title: "How to use event-triggered Netlify Functions"
description: "Learn how to automatically trigger Netlify Functions on specific Netlify events"
source: "https://www.netlify.com/blog/2021/07/21/how-to-use-event-triggered-netlify-functions/"
last_updated: "2026-07-10T19:43:58.000Z"
---
Netlify Functions are serverless functions you can write in Node.js, TypeScript or Go. You can use them to fetch data from APIs, send notification emails, and much more. But did you know they can be triggered automatically by certain Netlify events?

Let’s go through a small demo showing you how to send a Slack notification with a GIF when a deploy fails.

## Events

We know naming things is hard so we’ve made it easier for you. The main difference with these functions is that they have to be named after the event you want to use.

For this Slack notification example, the function file needs to be named `deploy-failed.js`.

There are many events that you can use to trigger a function like this, including events related to deployments, split tests, form submissions, and user authentication.

You can find the [full list of available events in the docs](https://docs.netlify.com/functions/trigger-on-events/).

If you would like to use [background functions](https://www.netlify.com/blog/2020/10/29/announcing-background-functions/) (which can run for longer than regular functions, and are useful for batch processing jobs), the naming convention is the same as other functions, you only need to add `-background` after the function name, so for example `deploy-failed-background.js`.

## Fetching data and sending a notification

In the `deploy-failed.js` file, I start by fetching a GIF using the [Giphy API](https://developers.giphy.com/docs/api/):

```
const response = await fetch(  `http://api.giphy.com/v1/gifs/random?tag=fail&api_key=${giphyApiKey}&limit=1`);const { data } = await response.json();
```

This returns a random ‘fail’ GIF.

Once it is available, we can do a `POST` request to the [Slack API](https://api.slack.com/) to send it to a channel:

```
await fetch(  `https://hooks.slack.com/services/${userID}/${channelID}/${slackApiSecret}`,  {    method: "POST",    headers: {      "Content-type": "application/json"    },    body: JSON.stringify({      text: data.url    })  });
```

And finally, we return the response from the function with an empty body:

```
return {  statusCode: 200,  body: JSON.stringify({})};
```

If you’ve written Netlify Functions before, you’ll notice that there is nothing different from a “normal” function, except the file naming convention.

Once this function is pushed to your Git provider and the site deploys, if it fails, a GIF will be sent to the Slack channel!

Here’s an example with cancelling a deploy:

![Triggering a deploy and cancelling it before it finishes triggers the function and posts a GIF on Slack](/v3/img/blog/event-triggered-function.gif)

Event-driven functions can be used to add all sorts of automation, observability, and integrations to your projects. How might you use them?

If you’d like to check the code, the [repo is available on GitHub](https://github.com/charliegerard/event-triggered-netlify-function).

Enjoy!

### Share

-   [X (fka Twitter)](https://twitter.com/intent/tweet?text=How to use event-triggered Netlify Functions&url=https://www.netlify.com/blog/2021/07/21/how-to-use-event-triggered-netlify-functions//)
-   [LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.netlify.com%2Fblog%2F2021%2F07%2F21%2Fhow-to-use-event-triggered-netlify-functions%2F%2F)
-   [Facebook](https://www.facebook.com/sharer.php?u=https://www.netlify.com/blog/2021/07/21/how-to-use-event-triggered-netlify-functions//)
-   [Bluesky](https://bsky.app/intent/compose?text=How to use event-triggered Netlify Functions+https://www.netlify.com/blog/2021/07/21/how-to-use-event-triggered-netlify-functions//)

* * *

### Tags

-   [Frontend](/blog/tags/frontend/)
-   [Engineering](/blog/tags/engineering/)
-   [Netlify Functions](/blog/tags/netlify-functions/)

## Keep reading

![](/images/blog-fallback-thumbnail.svg)

News & Announcements April 19, 2021

[

### Announcing Native TypeScript Support for Netlify Functions

](/blog/2021/04/19/announcing-native-typescript-support-for-netlify-functions/)

-   ![Profile picture of Eduardo Bouças](/_astro/52958f21e8450baf6d8e60302341a984e220c0cd-512x512_13VDlu.webp)
    
    Eduardo Bouças
    

![](/images/blog-fallback-thumbnail.svg)

Guides & Tutorials September 14, 2018

[

### Forms and Functions

](/blog/2018/09/14/forms-and-functions/)

-   ![Profile picture of Netlify team](/_astro/2ded7a52db41c7613be0baa648ac9bf9c1e8a985-300x300_DNhVu.svg)
    
    Netlify team
    

## Recent posts

News & Announcements June 25, 2026

[

### Netlify Functions, designed for Agent Experience

](/blog/netlify-functions-designed-for-agent-experience)

-   ![Profile picture of Eduardo Bouças](/_astro/52958f21e8450baf6d8e60302341a984e220c0cd-512x512_13VDlu.webp)
    
    Eduardo Bouças
    

News & Announcements June 24, 2026

[

### How we measure Netlify’s Agent Experience

](/blog/how-we-measure-netlify-agent-experience)

-   ![Profile picture of Sean Roberts](/_astro/bbf2243f8171dbddd80ab2103622106cef84d125-512x512_Z1d2LKE.webp)
    
    Sean Roberts
    

Guides & Tutorials May 15, 2026

[

### How to build a real-time AI chatbot in minutes with Netlify Agent Runners (no backend)

](/blog/how-to-build-a-real-time-ai-chatbot-in-minutes-with-netlify-agent-runners-no-backend)

-   ![Profile picture of Nahrin Jalal](/_astro/f0e7c8f227a03fe58340c99ef5439d5a896c0733-272x272_Z23kDpD.webp)
    
    Nahrin Jalal
    

![](/_astro/3f255b372fa958df35802666ee33b4609b2d71bd-1200x1586_1VtE2D.webp)

### How do the best dev and marketing teams work together?

[Access the report](https://www.netlify.com/reports/2024-leadership-trend-report/access/)