You are currently viewing How To Schedule An AWS CodeBuild Using Trigger

How To Schedule An AWS CodeBuild Using Trigger

How To Schedule An AWS CodeBuild Using Trigger

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed different components of a buildspec file in CodeBuild.

In this blog post, we will discuss how to schedule an AWS CodeBuild using a trigger. You can create a trigger on a project to schedule a build once every hour, day, or week. You can also create a trigger using a custom rule with an Amazon CloudWatch cron expression. For example, using a cron expression, you can schedule a build at a specific time every weekday.

Next, we are going to create a CodeBuild project and then schedule the project build. Unfortunately at the time of writing this blog post, I am not able to find any AWS CLI option to schedule the build trigger, hence we will use both AWS CLI and AWS console for this demo. If you are aware of any such option in AWS CLI then kindly share in the comment section.

How To Schedule An AWS CodeBuild Using Trigger:


AWS CLI installed and configured. You can follow the below blog post to install and configure AWS CLI.

Git installed and configured.

Step 1: Setup AWS CodeCommit repository to host your CodeBuild source code.

Note: CodeBuild supports S3 bucket, CodeCommit, GitHub, and Bitbucket as your build source code location. In this demo we are using CodeCommit to show the integration of CodeCommit with CodeBuild.

Step 2: Create an IAM role for AWS CodeBuild.

Step 3: Create an S3 bucket to store your build outcome (artifacts).

Note: We can deploy this artifact using CodeDeploy in CodePipeline, which will be covered under CodeDeploy.

Step 4: Create a CodeBuild build project.

Step 5: Log in to your AWS console and navigate to AWS CodeBuild, select your project, and click on the ‘Build trigger’ tab and click on ‘Create trigger’.

How To Schedule An AWS CodeBuild Using Trigger

Step 6: Provide a name, description, and schedule for your build trigger and click on ‘Create trigger’.

AWS CodeBuild supports cron expression in the form of cron(Minutes Hours Day_of_month Month Day_of_week Year). To get more details you can refer to AWS documentation.

How To Schedule An AWS CodeBuild Using Trigger

Our trigger created successfully.

How To Schedule An AWS CodeBuild Using Trigger

Next, you can either wait for the trigger to get executed or execute the build manually. If you want to wait for the trigger then don’t forget to delete all the resources afterward or you will get charged.

Step 8: Start your CodeBuild build project.

Note: Additional charges apply to build your source code. CodeBuild builds is charged on per minutes basis and you get 120 free every month for small compute which is used in this demo.

Step 9: Get your build artifacts and logs.

Step 10: Cleanup.

Hope you have enjoyed this blog post. To get more details on AWS CodeBuild, please refer below AWS documentation