Amazon CloudWatch Events
User Guide

Tutorial: Schedule Automated Builds Using AWS CodeBuild

In the example in this tutorial, you schedule AWS CodeBuild to run a build every week night at 8PM GMT. You also pass a constant to AWS CodeBuild to be used for this scheduled build.

To create a rule scheduling an AWS CodeBuild project build nightly at 8PM

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation pane, choose Events, Create rule.

  3. For Event Source, do the following:

    1. Choose Schedule.

    2. Choose Cron expression and specify the following as the expression: 0 20 ? * MON-FRI *. For more information about cron expressions, see Schedule Expressions for Rules.

  4. For Targets, choose Add target, CodeBuild project.

  5. For Project ARN, type the ARN of the build project.

  6. In this tutorial, we add the optional step of passing a parameter to AWS CodeBuild, to override the default. This is not required when you set AWS CodeBuild as the target. To pass the parameter, choose Configure input, Constant (JSON text).

    In the box under Constant (JSON text), type the following to set the timeout override to 30 minutes for these scheduled builds: { "timeoutInMinutesOverride": 30 }

    For more information about the parameters you can pass, see StartBuild. You cannot pass the projectName parameter in this field. Instead, you specify the project using the ARN in Project ARN.

  7. CloudWatch Events can create the IAM role needed for your build project to run:

    • To create an IAM role automatically, choose Create a new role for this specific resource.

    • To use an IAM role that you created before, choose Use existing role. This must be a role that already has sufficient permissions to invoke the build. CloudWatch Events does not grant additional permissions to the role that you select.

  8. Choose Configure details

  9. For Rule definition, type a name and description for the rule.

  10. Choose Create rule.