Skip to content

EventBridge scheduler-triggered Function

This guide describes a scheduled AWS architecture where EventBridge scheduler triggers a Lambda function at defined intervals to start a deployment workflow.

The setup leverages BYM’s Terraform modules setup terraform-byks-module which provision the necessary IAM roles and permissions and apply the standard default configuration.

source directory structure
├──application-name/
  ├── byks_application_name.tf
        lambda_functions {
            schedules {}
        }
  └── locals.tf

The Lambda function and the scheduler schedule

Add the following code to byks_kattehotell.tf file to configure a Lambda function and an EventBridge schedule.

byks_kattehotell.tf
module "byks_kattehotell" {
    source = "git@github.com:BYM-IKT/terraform-byks-module.git?ref=v12"
    # ...

    lambda_functions = {
        kattehotell_reservations  = {
            override_name         = "kattehotell-refresh-user-roles"
            ecr_uri               = data.terraform_remote_state.shared_kattehotell_ecr.outputs.kattehotell_add_visitors_ecr_repo
            image_tag             = var.environment
            environment_variables = local.kattehotell_refresh_user_role_environment_variables
            schedules = {
                refresh_user_roles = {
                    enabled               = true
                    expression         = "cron(0 0 * * ? *)"
                }
            }
        }    
    }
}
The required environment variables for the Lambda function can be provided in the locals.tf file inside kattehotell_refresh_user_role_environment_variables section.

locals.tf
1
2
3
4
5
locals {
  kattehotell_refresh_user_role_environment_variables = {
    ...
  }
}

Result:

The Lambda function kattehotell-refresh-user-roles is triggered once every hour to start a job.