

# Logging and monitoring in AWS CodeBuild
<a name="logging-monitoring"></a>

Logging and monitoring is an important part of maintaining the reliability, availability, and performance of AWS CodeBuild and your AWS solutions. You should collect monitoring data from all of the parts of your AWS solution so that you can more easily debug a multi-point failure, if one occurs. AWS provides the following tools for monitoring your CodeBuild resources and builds and for responding to potential incidents. 

**Topics**
+ [Log AWS CodeBuild API calls with AWS CloudTrail](cloudtrail.md)
+ [Monitor CodeBuild builds with CloudWatch](monitoring-builds.md)

# Log AWS CodeBuild API calls with AWS CloudTrail
<a name="cloudtrail"></a>

AWS CodeBuild is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in CodeBuild. CloudTrail captures all API calls for CodeBuild as events, including calls from the CodeBuild console and from code calls to the CodeBuild APIs. If you create a trail, you can enable continuous delivery of CloudTrail events to an S3 bucket, including events for CodeBuild. If you don't configure a trail, you can still view the most recent events in the CloudTrail console in **Event history**. Using the information collected by CloudTrail, you can determine the request that was made to CodeBuild, the IP address from which the request was made, who made the request, when it was made, and additional details. 

To learn more about CloudTrail, see the [AWS CloudTrail User Guide](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/).

**Topics**
+ [About AWS CodeBuild information in CloudTrail](service-name-info-in-cloudtrail.md)
+ [About AWS CodeBuild log file entries](understanding-service-name-entries.md)

# About AWS CodeBuild information in CloudTrail
<a name="service-name-info-in-cloudtrail"></a>

CloudTrail is enabled on your AWS account when you create the account. When activity occurs in CodeBuild, that activity is recorded in a CloudTrail event along with other AWS service events in **Event history**. You can view, search, and download recent events in your AWS account. For more information, see [Viewing events with CloudTrail event history](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html) in the *AWS CloudTrail User Guide*. 

For an ongoing record of events in your AWS account, including events for CodeBuild, create a trail. A trail enables CloudTrail to deliver log files to an S3 bucket. By default, when you create a trail in the console, the trail applies to all regions. The trail logs events from all regions in the AWS partition and delivers the log files to the S3 bucket that you specify. You can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see: 
+ [Overview for creating a trail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ [CloudTrail supported services and integrations](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html#cloudtrail-aws-service-specific-topics-integrations)
+ [Configuring Amazon SNS notifications for CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/getting_notifications_top_level.html)
+ [Receiving CloudTrail log files from multiple regions](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html) and [Receiving CloudTrail log files from multiple accounts](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)

All CodeBuild actions are logged by CloudTrail and are documented in the [CodeBuild API Reference](https://docs.aws.amazon.com/codebuild/latest/APIReference/). For example, calls to the `CreateProject` (in the AWS CLI, `create-project`), `StartBuild` (in the AWS CLI, `start-project`), and `UpdateProject` (in the AWS CLI, `update-project`) actions generate entries in the CloudTrail log files. 

Every event or log entry contains information about who generated the request. The identity information helps you determine the following: 
+ Whether the request was made with root or user credentials.
+ Whether the request was made with temporary security credentials for a role or federated user.
+ Whether the request was made by another AWS service.

For more information, see the [CloudTrail userIdentity element](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)in the *AWS CloudTrail User Guide*.

# About AWS CodeBuild log file entries
<a name="understanding-service-name-entries"></a>

A trail is a configuration that enables delivery of events as log files to an S3 bucket that you specify. CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested action, the date and time of the action, request parameters, and so on. CloudTrail log files are not an ordered stack trace of the public API calls, so they do not appear in any specific order. 

**Note**  
 To protect sensitive information, the following are hidden in CodeBuild logs:   
 AWS access key IDs. For more information, see [Managing Access Keys for IAM Users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html) in the *AWS Identity and Access Management User Guide*. 
 Strings specified using the Parameter Store. For more information, see [Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html) and [Systems Manager Parameter Store Console Walkthrough](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-walk.html#sysman-paramstore-console) in the *Amazon EC2 Systems Manager User Guide*. 
 Strings specified using AWS Secrets Manager. For more information, see [Key management](security-key-management.md). 

The following example shows a CloudTrail log entry that demonstrates creating a build project in CodeBuild.

```
{    
  "eventVersion": "1.05",   
  "userIdentity": {       
    "type": "FederatedUser",       
    "principalId": "account-ID:user-name",       
    "arn": "arn:aws:sts::account-ID:federated-user/user-name",       
    "accountId": "account-ID",       
    "accessKeyId": "access-key-ID",       
    "sessionContext": {
      "attributes": {
        "mfaAuthenticated": "false",
        "creationDate": "2016-09-06T17:59:10Z"
      },
      "sessionIssuer": {
        "type": "IAMUser",
        "principalId": "access-key-ID",
        "arn": "arn:aws:iam::account-ID:user/user-name",
        "accountId": "account-ID",
        "userName": "user-name"
      }       
    }   
  },   
  "eventTime": "2016-09-06T17:59:11Z",   
  "eventSource": "codebuild.amazonaws.com",   
  "eventName": "CreateProject",   
  "awsRegion": "region-ID",   
  "sourceIPAddress": "127.0.0.1",   
  "userAgent": "user-agent",   
  "requestParameters": {       
    "awsActId": "account-ID"   
  },   
  "responseElements": {       
    "project": {
      "environment": {
        "image": "image-ID",
        "computeType": "BUILD_GENERAL1_SMALL",
        "type": "LINUX_CONTAINER",
        "environmentVariables": []
      },
      "name": "codebuild-demo-project",
      "description": "This is my demo project",
      "arn": "arn:aws:codebuild:region-ID:account-ID:project/codebuild-demo-project:project-ID",
      "encryptionKey": "arn:aws:kms:region-ID:key-ID",
      "timeoutInMinutes": 10,
      "artifacts": {
        "location": "arn:aws:s3:::codebuild-region-ID-account-ID-output-bucket",
        "type": "S3",
        "packaging": "ZIP",
        "outputName": "MyOutputArtifact.zip"
      }, 
      "serviceRole": "arn:aws:iam::account-ID:role/CodeBuildServiceRole",
      "lastModified": "Sep 6, 2016 10:59:11 AM",
      "source": {      
        "type": "GITHUB",
        "location": "https://github.com/my-repo.git"
      },
      "created": "Sep 6, 2016 10:59:11 AM"       
    }   
  },   
  "requestID": "9d32b228-745b-11e6-98bb-23b67EXAMPLE",   
  "eventID": "581f7dd1-8d2e-40b0-aeee-0dbf7EXAMPLE",   
  "eventType": "AwsApiCall",   
  "recipientAccountId": "account-ID" 
}
```

# Monitor CodeBuild builds with CloudWatch
<a name="monitoring-builds"></a>

You can use Amazon CloudWatch to watch your builds, report when something is wrong, and take automatic actions when appropriate. You can monitor your builds at two levels: 

Project level  
These metrics are for all builds in the specified project. To see metrics for a project, specify `ProjectName` for the dimension in CloudWatch.

AWS account level  
These metrics are for all builds in an account. To see metrics at the AWS account level, do not enter a dimension in CloudWatch. Build resource utilization metrics are not available at the AWS account level.

CloudWatch metrics show the behavior of your builds over time. For example, you can monitor: 
+  How many builds were attempted in a build project or an AWS account over time. 
+  How many builds were successful in a build project or an AWS account over time. 
+  How many builds failed in a build project or an AWS account over time. 
+  How much time CodeBuild spent running builds in a build project or an AWS account over time. 
+ Build resource utilization for a build or an entire build project. Build resource utilization metrics include metrics such as CPU, memory, and storage utilization.

 For more information, see [View CodeBuild metrics](monitoring-metrics.md). 

# CodeBuild CloudWatch metrics
<a name="cloudwatch_metrics-codebuild"></a>

 The following metrics can be tracked per AWS account or build project. For more information about using CloudWatch with CodeBuild, see [Monitor CodeBuild builds with CloudWatch](monitoring-builds.md).

BuildDuration  
Measures the duration of the build's `BUILD` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

Builds  
 Measures the number of builds triggered.   
 Units: Count   
 Valid CloudWatch statistics: Sum 

DownloadSourceDuration  
Measures the duration of the build's `DOWNLOAD_SOURCE` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

Duration  
 Measures the duration of all builds over time.   
 Units: Seconds   
 Valid CloudWatch statistics: Average (recommended), Maximum, Minimum 

FailedBuilds  
 Measures the number of builds that failed because of client error or a timeout.   
 Units: Count   
 Valid CloudWatch statistics: Sum 

FinalizingDuration  
Measures the duration of the build's `FINALIZING` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

InstallDuration  
Measures the duration of the build's `INSTALL` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

PostBuildDuration  
Measures the duration of the build's `POST_BUILD` phase  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

PreBuildDuration  
Measures the duration of the build's `PRE_BUILD` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

ProvisioningDuration  
Measures the duration of the build's `PROVISIONING` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

QueuedDuration  
Measures the duration of the build's `QUEUED` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

SubmittedDuration  
Measures the duration of the build's `SUBMITTED` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

SucceededBuilds  
 Measures the number of successful builds.   
 Units: Count   
 Valid CloudWatch statistics: Sum 

UploadArtifactsDuration  
Measures the duration of the build's `UPLOAD_ARTIFACTS` phase.  
Units: Seconds  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

# CodeBuild CloudWatch resource utilization metrics
<a name="cloudwatch-utilization-metrics"></a>

**Note**  
CodeBuild resource utilization metrics are only available in the following regions:  
Asia Pacific (Tokyo) Region
Asia Pacific (Seoul) Region
Asia Pacific (Mumbai) Region
Asia Pacific (Singapore) Region
Asia Pacific (Sydney) Region
Canada (Central) Region
Europe (Frankfurt) Region
Europe (Ireland) Region
Europe (London) Region
Europe (Paris) Region
South America (São Paulo) Region
US East (N. Virginia) Region
US East (Ohio) Region
US West (N. California) Region
US West (Oregon) Region

The following resource utilization metrics can be tracked. For more information about using CloudWatch with CodeBuild, see [Monitor CodeBuild builds with CloudWatch](monitoring-builds.md).

CPUUtilized  
The number of CPU units of allocated processing used by the build container.  
Units: CPU units  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

CPUUtilizedPercent  
The percentage of allocated processing used by the build container.  
Units: Percent  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

MemoryUtilized  
The number of megabytes of memory used by the build container.  
Units: Megabytes  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

MemoryUtilizedPercent  
The percentage of allocated memory used by the build container.  
Units: Percent  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

StorageReadBytes  
The storage read speed used by the build container.  
Units: Bytes/second  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

StorageWriteBytes  
The storage write speed used by the build container.  
Units: Bytes/second  
Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

# CodeBuild CloudWatch dimensions
<a name="codebuild-cloudwatch-dimensions"></a>

CodeBuild provides the following CloudWatch metric dimensions. If none of these are specified, the metrics are for the current AWS account. 

BuildId, BuildNumber, ProjectName  
Metrics are provided for a build identifier, build number, and project name.

ProjectName  
Metrics are provided for a project name.

# CodeBuild CloudWatch alarms
<a name="codebuild_cloudwatch_alarms"></a>

 You can use the CloudWatch console to create alarms based on CodeBuild metrics so you can react if something goes wrong with your builds. The two metrics that are most useful with alarms are described in the following bullets. For more information about using CloudWatch with CodeBuild, see [Monitor CodeBuild builds with CloudWatch](monitoring-builds.md). 
+  `FailedBuild`. You can create an alarm that is triggered when a certain number of failed builds are detected within a predetermined number of seconds. In CloudWatch, you specify the number of seconds and how many failed builds trigger an alarm. 
+  `Duration`. You can create an alarm that is triggered when a build takes longer than expected. You specify how many seconds must elapse after a build is started and before a build is completed before the alarm is triggered. 

 For information about how to create alarms for CodeBuild metrics, see [Monitor CodeBuild builds with CloudWatch alarms](monitoring-alarms.md). For more information about alarms, see [Creating Amazon CloudWatch alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) in the *Amazon CloudWatch User Guide*. 

# View CodeBuild metrics
<a name="monitoring-metrics"></a>

 AWS CodeBuild monitors functions on your behalf and reports metrics through Amazon CloudWatch. These metrics include the number of total builds, failed builds, successful builds, and the duration of builds. 

 You can use the CodeBuild console or the CloudWatch console to monitor metrics for CodeBuild. The following procedures show you how to view metrics. 

**Topics**
+ [View build metrics (CodeBuild console)](#metrics-in-codebuild-console)
+ [View build metrics (Amazon CloudWatch console)](#metrics-in-cloudwatch-console)

## View build metrics (CodeBuild console)
<a name="metrics-in-codebuild-console"></a>

**Note**  
You can't customize the metrics or the graphs used to display them in the CodeBuild console. If you want to customize the display, use the Amazon CloudWatch console to view your build metrics. 

### Account-level metrics
<a name="codebuild-console-account-level-metrics"></a><a name="cw-account-metrics-codebuild-console"></a>

**To view AWS account-level metrics**

1. Sign in to the AWS Management Console and open the AWS CodeBuild console at [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home).

1.  In the navigation pane, choose **Account metrics**. 

### Project-level metrics
<a name="codebuild-console-project-level-metrics"></a><a name="cw-project-codebuild-console"></a>

**To view project-level metrics**

1. Sign in to the AWS Management Console and open the AWS CodeBuild console at [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home).

1.  In the navigation pane, choose **Build projects**. 

1.  In the list of build projects, in the **Name** column, choose the project where you want to view metrics. 

1.  Choose the **Metrics** tab. 

## View build metrics (Amazon CloudWatch console)
<a name="metrics-in-cloudwatch-console"></a>

You can customize the metrics and the graphs used to display them with the CloudWatch console. 

### Account-level metrics
<a name="cloudwatch-console-account-level-metrics"></a><a name="cw-account-cloudwatch-console"></a>

**To view account-level metrics**

1. Sign in to the AWS Management Console and open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1.  In the navigation pane, choose **Metrics**. 

1.  On the **All metrics** tab, choose **CodeBuild**.   
![\[How to view CodeBuild metrics.\]](http://docs.aws.amazon.com/codebuild/latest/userguide/images/codebuild-metrics-in-cw.png)

1.  Choose **Account Metrics**. 

1.  Choose one or more projects and metrics. For each project, you can choose the **SucceededBuilds**, **FailedBuilds**, **Builds**, and **Duration** metrics. All selected project and metric combinations are displayed in the graph on the page. 

### Project-level metrics
<a name="cloudwatch-console-project-level-metrics"></a><a name="cw-project-cloudwatch-console"></a>

**To view project-level metrics**

1. Sign in to the AWS Management Console and open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1.  In the navigation pane, choose **Metrics**. 

1.  On the **All metrics** tab, choose **CodeBuild**.   
![\[How to view CodeBuild metrics.\]](http://docs.aws.amazon.com/codebuild/latest/userguide/images/codebuild-metrics-in-cw.png)

1.  Choose **By Project**. 

1.  Choose one or more project and metric combinations. For each project, you can choose the **SucceededBuilds**, **FailedBuilds**, **Builds**, and **Duration** metrics. All selected project and metric combinations are displayed in the graph on the page. 

1.  (Optional) You can customize your metrics and graphs. For example, from the drop-down list in the **Statistic** column, you can choose a different statistic to display. Or from the drop-down menu in the **Period** column, you can choose a different time period to use to monitor the metrics. 

   For more information, see [Graph metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph_metrics.html) and [View available metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/viewing_metrics_with_cloudwatch.html) in the *Amazon CloudWatch User Guide*. 

# View CodeBuild resource utilization metrics
<a name="monitoring-utilization-metrics"></a>

AWS CodeBuild monitors build resource utilization on your behalf and reports metrics through Amazon CloudWatch. These include metrics such as CPU, memory, and storage utilization.

**Note**  
CodeBuild resource utilization metrics are only recorded for builds that run for more than one minute.

You can use the CodeBuild console or the CloudWatch console to monitor resource utilization metrics for CodeBuild. 

**Note**  
CodeBuild resource utilization metrics are only available in the following regions:  
Asia Pacific (Tokyo) Region
Asia Pacific (Seoul) Region
Asia Pacific (Mumbai) Region
Asia Pacific (Singapore) Region
Asia Pacific (Sydney) Region
Canada (Central) Region
Europe (Frankfurt) Region
Europe (Ireland) Region
Europe (London) Region
Europe (Paris) Region
South America (São Paulo) Region
US East (N. Virginia) Region
US East (Ohio) Region
US West (N. California) Region
US West (Oregon) Region

The following procedures show you how to access your resource utilization metrics.

**Topics**
+ [Access resource utilization metrics (CodeBuild console)](#utilization-metrics-codebuild-console)
+ [Access resource utilization metrics (Amazon CloudWatch console)](#utilization-metrics-cloudwatch-console)

## Access resource utilization metrics (CodeBuild console)
<a name="utilization-metrics-codebuild-console"></a>

**Note**  
You can't customize the metrics or the graphs used to display them in the CodeBuild console. If you want to customize the display, use the Amazon CloudWatch console to view your build metrics. 

### Project-level resource utilization metrics
<a name="codebuild-console-project-level-utilization"></a>

**To access project-level resource utilization metrics**

1. Sign in to the AWS Management Console and open the AWS CodeBuild console at [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home).

1. In the navigation pane, choose **Build projects**.

1. In the list of build projects, in the **Name** column, choose the project you want to view the utilization metrics for.

1. Choose the **Metrics** tab. The resource utilization metrics are displayed in the **Resource utilization metrics** section.

1. To view the project-level resource utilization metrics in the CloudWatch console, choose **View in CloudWatch** in the **Resource utilization metrics** section.

### Build-level resource utilization metrics
<a name="codebuild-console-build-level-utilization"></a>

**To access build-level resource utilization metrics**

1. Sign in to the AWS Management Console and open the AWS CodeBuild console at [https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home).

1. In the navigation pane, choose **Build history**.

1. In the list of builds, in the **Build run** column, choose the build you want to view the utilization metrics for.

1. Choose the **Resource utilization** tab.

1. To view the build-level resource utilization metrics in the CloudWatch console, choose **View in CloudWatch** in the **Resource utilization metrics** section.

## Access resource utilization metrics (Amazon CloudWatch console)
<a name="utilization-metrics-cloudwatch-console"></a>

The Amazon CloudWatch console can be used to access CodeBuild resource utilization metrics.

### Project-level resource utilization metrics
<a name="cloudwatch-console-project-level-utilization"></a><a name="cw-project-cloudwatch-console"></a>

**To access project-level resource utilization metrics**

1. Sign in to the AWS Management Console and open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1. In the navigation pane, choose **Metrics**.

1. On the **All metrics** tab, choose **CodeBuild**.  
![\[Console screenshot showing the CodeBuild option located on the All metrics tab.\]](http://docs.aws.amazon.com/codebuild/latest/userguide/images/codebuild-metrics-in-cw.png)

1. Choose **By Project**.

1. Choose one or more project and metric combinations to add to the graph. All selected project and metric combinations are displayed in the graph on the page.

1. (Optional) You can customize your metrics and graphs from the **Graphed metrics** tab. For example, from the drop-down list in the **Statistic** column, you can choose a different statistic to display. Or from the drop-down menu in the **Period** column, you can choose a different time period to use to monitor the metrics. 

   For more information, see [Graphing metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph_metrics.html) and [Viewing available metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/viewing_metrics_with_cloudwatch.html) in the *Amazon CloudWatch User Guide*. 

### Build-level resource utilization metrics
<a name="cloudwatch-console-build-level-utilization"></a>

**To access build-level resource utilization metrics**

1. Sign in to the AWS Management Console and open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1. In the navigation pane, choose **Metrics**.

1. On the **All metrics** tab, choose **CodeBuild**.  
![\[Console screenshot showing the CodeBuild option located on the All metrics tab.\]](http://docs.aws.amazon.com/codebuild/latest/userguide/images/codebuild-metrics-in-cw.png)

1. Choose **BuildId, BuildNumber, ProjectName**.

1. Choose one or more build and metric combinations to add to the graph. All selected build and metric combinations are displayed in the graph on the page.

1. (Optional) You can customize your metrics and graphs from the **Graphed metrics** tab. For example, from the drop-down list in the **Statistic** column, you can choose a different statistic to display. Or from the drop-down menu in the **Period** column, you can choose a different time period to use to monitor the metrics. 

   For more information, see [Graphing metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph_metrics.html) and [Viewing available metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/viewing_metrics_with_cloudwatch.html) in the *Amazon CloudWatch User Guide*. 

# Monitor CodeBuild builds with CloudWatch alarms
<a name="monitoring-alarms"></a>

 You can create a CloudWatch alarm for your builds. An alarm watches a single metric over a period of time that you specify and performs one or more actions based on the value of the metric relative to a specified threshold over a number of time periods. Using native CloudWatch alarm functionality, you can specify any of the actions supported by CloudWatch when a threshold is exceeded. For example, you can specify that an Amazon SNS notification is sent when more than three builds in your account fail within fifteen minutes. 

**To create a CloudWatch alarm for a CodeBuild metric**

1. Sign in to the AWS Management Console and open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1.  In the navigation pane, choose **Alarms**. 

1.  Choose **Create Alarm**. 

1.  Under **CloudWatch Metrics by Category**, choose **CodeBuild Metrics**. If you know you want only project-level metrics, choose **By Project**. If you know you want only account-level metrics, choose **Account Metrics**. 

1.  On **Create Alarm**, if it isn't already selected, choose **Select Metric**. 

1.  Choose a metric for which you want to create an alarm. The options are **By Project** or **Account Metrics**. 

1.  Choose **Next** or **Define Alarm** and then create your alarm. For more information, see [Creating Amazon CloudWatch alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) in the *Amazon CloudWatch User Guide*. For more information about setting up Amazon SNS notifications when an alarm is triggered, see [Set up Amazon SNS notifications](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html) in the *Amazon SNS Developer Guide*. 

1.  Choose **Create Alarm**. 