Wednesday 14th October 2026
Ho Chi Minh, Vietnam

1. Introduction

Do you need to run a background task every few minutes — like syncing data, sending reports, or hitting an external API? AWS Lambda and EventBridge (formerly CloudWatch Events) offer a simple, serverless way to schedule jobs without managing servers.

In this article, I’ll show you how to spin up a scheduled Lambda function using Terraform — all in under 5 minutes.

2. What We’re Building

We’ll use:

  • AWS Lambda to execute your custom logic
  • EventBridge to define a time-based schedule
  • Terraform to provision everything as code

The result: A serverless scheduler that you can easily deploy, update, and manage using infrastructure as code.


3. Prerequisites

Before we start, make sure you have:

  • Terraform installed
  • AWS CLI configured (aws configure)
  • An IAM user with permissions for Lambda, IAM, and EventBridge

4. Let’s start

Step 1: Write Terraform Code

Create a new folder and add a file named main.tf with the following content:

Step 2: Create Your Lambda Function

In the same folder, create a Python file named lambda_function.py:

Then zip it:

Step 3: Deploy with Terraform

Run the following commands to provision everything:

Terraform will:

  • Create an IAM role
  • Deploy your Lambda
  • Set up an EventBridge rule to trigger it every 5 minutes
  • Give EventBridge permission to invoke your Lambda

5. Conclusion

In just a few minutes, you now have a scheduled Lambda running every 5 minutes — and you didn’t have to touch the AWS Console at all:

  • No EC2 instances to manage
  • No cron job servers to maintain
  • Scalable and cost-effective (you only pay when Lambda runs)
  • Infrastructure-as-Code makes it version-controlled and replicable

You can verify it by checking CloudWatch Logs in the AWS Console to see the function being invoked. The source code can be found here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top