[AWS Lab] Scheduled Lambda Invocation – EventBridge

In this lab, we will learn how to periodically invoke a lambda function via Amazon EventBridge.

  • Overview
  • Source: EventBridge
    • Build a custom Rule – Scheduling
  • Target: Lambda – Function
    • returns the current date time
    • Python

1. Lambda – Create a Function

  • Function Name: “logDateTime
  • Runtime: Python 3.9

2. Lambda – Function Code (Python)

  • Type the following code
  • Click “Deploy
import json
from datetime import datetime

def lambda_handler(event, context):
  return {
    'statusCode': 200,   
    'body': json.dumps(datetime.now().strftime("%m/%d/%Y %H:%M:%S"))

3. EventBridge – Create a Rule

  1. Click the “Rules” menu on the left pane
  2. Click “Create Rule
    • Name: “datetime-rule
    • Event bus: select “default
    • Rule Type: “Schedule
    • Click “Continue in EventBridge Scheduler
  3. Specify schedule detail
    • Check “Recurring schedule
    • Schedule Type: “Cron-based schedule
    • Cron expression: every minute
    • Flexible time window: “Off
  4. Select Target(s)
    • Target: “Lambda Invoke
    • Lambda Function: “logDateTime
    • Input: Empty
  5. Settings
    • Enable schedule: “Enable
    • Check “Create new role for this schedule

5. CouldWatch – Check the Lambda logs

  1. On the Lambda function page, click the “Monitor” tab
  2. Check some metrics on the page
  3. Click the “View logs in the CloudWatch” button
  4. On the CloudWatch page, click the “Log stream
  5. Check the logs

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s