Tutorial

12 Days of DigitalOcean (Day 5) - Automating Birthday Reminders with Daily Triggers

12 Days of DigitalOcean (Day 5) - Automating Birthday Reminders with Daily Triggers

Welcome to Day 5 of 12 Days of DigitalOcean! Yesterday, you set up your Birthday Reminder Service to run on DigitalOcean Functions, meaning it’s now serverless and cloud-ready. 🎉 Today, you will be taking it a step further by automating it to run on its own schedule—no manual input required.

By the end of this guide, your service (or any other function you’re working on) will run automatically at a set time every day. That means no more remembering to trigger it yourself—it just works.

Why Automate?

Deploying your function to the cloud was a big win yesterday, but having to run it manually defeats the purpose of automation. Today’s focus is on scheduling the service to run automatically—like clockwork—so you can set it and forget it. DigitalOcean Functions has built-in scheduling using Triggers for this exact purpose, and you have two ways to set it up.

🚀 What You’ll Learn

By the end of today, you’ll know how to:

  1. Set up a daily trigger to run your function automatically.
  2. Learn two ways to do this—through the DigitalOcean Control Panel or with the doctl CLI and project.yml.
  3. Test the setup to make sure it works.

🛠 What You’ll Need

Before getting started, ensure you have the following:

  1. A function already deployed on DigitalOcean (e.g., the Birthday Reminder Service from Day 4: Building a Birthday Reminder Service) to automate with triggers.
  2. If using the doctl CLI, you’ll need the project.yml file for your function. You can check out Day 4 for instructions on installing and setting up the doctl CLI, and creating the project.yml file.

🧑‍🍳 Recipe for Day 5: Automating Functions with Triggers

Step 1: Set Up a Trigger for Your Function

DigitalOcean gives you two options for setting up triggers:

  1. Option 1: Use the Control Panel for quick and easy setup.
  2. Option 2: Use the doctl CLI for more robust and programmatic control.

Warning: Remember that triggers created in the Control Panel are lost if you redeploy the function using the CLI. If you’ll be redeploying often, use Option 2 to add triggers directly to the project.yml file.

Option 1: Using the Control Panel to Create a Trigger

The easiest way to set up a trigger is through the DigitalOcean Control Panel. It’s quick, requires no setup, and is ideal for simple one-off configurations.

  • Navigate to the main Functions page in the DigitalOcean dashboard.
  • Find your function (e.g., reminders/birthdays) and click the Triggers tab.

DigitalOcean Functions dashboard showing the Triggers tab for managing function triggers

  • Click Create Trigger, add a Name for your trigger. This can be anything descriptive, like daily-birthday-trigger. The name must contain only alphanumeric characters, dashes, and periods.
  • Add a cron expression to set the schedule. For example, 0 9 * * * means the function will run every day at 9:00 AM.

Note: If you not sure how cron works? Check out crontab.guru for a handy guide.

Create Trigger modal in the DigitalOcean dashboard, with fields for entering the trigger name, cron expression, and optional payload

  • Save the trigger.

Once you’ve created your trigger, it’s a good idea to test it to ensure everything works as expected. Jump to the Test the Automation section below to learn how.

Warning: While the dashboard is simple and effective, any triggers you create here will be overwritten or deleted if you redeploy the function using the CLI. For frequent updates or programmatic deployments, skip to Option 2.

Option 2: Using the doctl CLI with project.yml

You can also create triggers by adding them directly to your project.yml file. This method is more reliable for frequent redeployments because it ensures your triggers are always included in the function’s configuration. Unlike the Control Panel option described earlier, this approach prevents triggers from being overwritten or lost during redeployments.

Here’s how you can set it up:

  • Open your project.yml file from Day 4: Deploying Birthday Notifications with DigitalOcean Functions. It might look something like this:

    packages:
      - name: reminders
        shared: false
        environment:
          DO_DB_NAME: "${DB_NAME}"
          DO_DB_USER: "${DB_USER}"
          DO_DB_PASSWORD: "${DB_PASSWORD}"
          DO_DB_HOST: "${DB_HOST}"
          DO_DB_PORT: "${DB_PORT}"
          TWILIO_ACCOUNT_SID: "${TWILIO_ACCOUNT_SID}"
          TWILIO_AUTH_TOKEN: "${TWILIO_AUTH_TOKEN}"
          TWILIO_PHONE_FROM: "${TWILIO_PHONE_FROM}"
          TWILIO_PHONE_TO: "${TWILIO_PHONE_TO}"
        functions:
          - name: birthdays
            runtime: python:default
    
  • Add a triggers section to your function configuration to define the schedule:

    triggers:
      - name: daily-birthday-trigger
        sourceType: scheduler
        sourceDetails:
        cron: "0 9 * * *"
    
  • Final updated project.yml file:

    packages:
      - name: reminders
        shared: false
        environment:
          DO_DB_NAME: "${DB_NAME}"
          DO_DB_USER: "${DB_USER}"
          DO_DB_PASSWORD: "${DB_PASSWORD}"
          DO_DB_HOST: "${DB_HOST}"
          DO_DB_PORT: "${DB_PORT}"
          TWILIO_ACCOUNT_SID: "${TWILIO_ACCOUNT_SID}"
          TWILIO_AUTH_TOKEN: "${TWILIO_AUTH_TOKEN}"
          TWILIO_PHONE_FROM: "${TWILIO_PHONE_FROM}"
          TWILIO_PHONE_TO: "${TWILIO_PHONE_TO}"
        functions:
          - name: birthdays
            runtime: python:default
            triggers:
              - name: daily-birthday-trigger
                sourceType: scheduler
                sourceDetails:
                  cron: "0 9 * * *"
    

    This tells DigitalOcean to run the birthdays function every day at 9:00 AM.

    1. triggers section: Defines the name, type, and schedule for the trigger. You can name your trigger anything descriptive, like daily-birthday-trigger.

    2. cron: Specifies the time the function will run daily in UTC. The cron expression 0 9 * * * for example, schedules the function to run every day at 9:00 AM.

  • Save the file and deploy it by running the following command from the directory containing the my-birthday-reminder-service folder:

    doctl serverless deploy my-birthday-reminder-service
    

    Important: Make sure to run the command from the parent directory, not inside the my-birthday-reminder-servicefolder. Running it from the wrong location can result in an error like this:

    ❯ doctl serverless deploy my-birthday-reminder-service
    Error: ENOENT: no such file or directory, lstat
    
  • Once the deployment is successful, you’ll see a confirmation message similar to this:

    Deployed functions
      - reminders/birthdays
    Deployed triggers:
      - daily-birthday-trigger
    

    Terminal output showing a successful deployment of the Birthday Reminder Service and confirmation of the deployed function and trigger

  • Go to your dashboard to verify that the trigger has been created under the Functions section.

DigitalOcean dashboard showing the Triggers section with a newly created trigger named 'daily-birthday-trigger' for the reminders/birthdays function

Pro Tip: To test your trigger, temporarily set the cron expression to a few minutes from now (e.g., 28 9 * * * if it’s 9:25 AM). After confirming that it works, update it back to your intended schedule and redeploy.

Step 2: Test the Automation

Let’s test your triggers to make sure they’re working. Instead of waiting for them to fire on their usual schedule, you can temporarily set them to run a few minutes from now. Here’s how to do it:

  • Set the cron expression for your trigger to a few minutes from the current time (in UTC). For example, if it’s 9:25 AM UTC, set the cron expression to 28 9 * * * so the function runs at 9:28 AM UTC.

    Note: Not sure how to convert your local time to UTC? Tools like Time Zone Converter can help.

  • Save the updated trigger (if using the Control Panel) or redeploy your updated project.yml file (if using the CLI):

    doctl serverless deploy my-birthday-reminder-service
    
  • Wait for the trigger to execute, then check the activation logs to confirm the function ran successfully:

    doctl serverless activations logs --function reminders/birthdays --last
    

Note: Activation logs record details about when your function was executed, including whether it ran successfully or encountered errors. They’re a helpful way to verify that your trigger fired at the scheduled time.

This command will return the details of the most recent activation of your function. For example, you might see something like this:

=== 59e8e4f482874d79a8e4f48287dd79ef success 12/23 07:46:33 reminders/birthdays:0.0.6
2024-12-23T07:46:33.323205805Z stdout: Message sent for Charlie Brown. Message SID: SM85f5caeb3ec09239e0d8bdaaba2b158b

Terminal output of the  command, showing details of the last activation of the reminders/birthdays function

This confirms that the trigger fired and the function was activated successfully! 🎉

Note: Once you’ve verified everything is working, update the cron expression to your intended schedule (e.g., 0 9 * * * for 9:00 AM UTC daily) and save or redeploy.

A Quick Note on Logs

While the activations logs command is a great way to check recent executions, sometimes you’ll need more detailed logs to debug or investigate issues with your function. DigitalOcean also provides options to forward these logs to external logging services, making monitoring and troubleshooting your application easier over time.

On Day 6, you will learn to view logs directly, interpret them effectively, and set up log forwarding to external services like Logtail or Papertrail. These tools will help you easily stay on top of your function’s performance.

🎁 Wrap-Up

Here’s what you accomplished today:

  1. You automated your Birthday Reminder Service (or any other function) to run daily.
  2. You learned two ways to set up triggers—through the Control Panel and with the doctl CLI.
  3. You tested your setup to ensure it works as expected.

Here are the previous tutorials from this series:

Up Next: Now that your service runs independently, the next step is monitoring it effectively. In the next tutorial, you will learn how to view your function logs and forward them to external services to simplify tracking and troubleshooting. See you then!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Default avatar

Sr Technical Writer

Senior Technical Writer @ DigitalOcean | 2x Medium Top Writers | 2 Million+ monthly views & 34K Subscribers | Ex Cloud Consultant @ AMEX | Ex SRE(DevOps) @ NUTANIX


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.