User Guide (API Version 2015-07-09)

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Create a CloudWatch Events Rule for a CodeCommit Source (Console)

To create a CloudWatch Events rule for use in CodePipeline operations

  1. Open the CloudWatch console at

  2. In the navigation pane, choose Events.

  3. Choose Create rule, and then under Event source, from Service Name, choose CodeCommit.

    The service name that you choose owns the event resource. For example, choose CodeCommit to trigger a pipeline when there are changes to the CodeCommit repository associated with a pipeline.

  4. From Event Type, choose CodeCommit Repository State Change.

                            Create repository state change rule
  5. To make a rule that applies to all repositories, choose Any resource.

    To make a rule that applies to one or more repositories, choose Specific resource(s) by ARN, and then enter the ARN.


    You can find the ARN for a CodeCommit repository on the Settings page in the CodeCommit console.

    To specify the branch to associate with the repository, choose Edit, and enter the resource type branch and branch name. Use the event pattern options for detail. The preceding example shows the detail options for a CodeCommit repository branch named master.

    The following is a sample CodeCommit event pattern in the Event window for a MyTestRepo repository with a branch named master:

    { "source": [ "aws.codecommit" ], "detail-type": [ "CodeCommit Repository State Change" ], "resources": [ "arn:aws:codecommit:us-west-2:80398EXAMPLE:MyTestRepo" ], "detail": { "referenceType": [ "branch" ], "referenceName": [ "master" ] } }

    Choose Save.

    In the Event Pattern Preview pane, view the rule.

  6. In Targets, choose CodePipeline.

  7. Enter the pipeline ARN for the pipeline to be started when triggered by this rule.


    You can find the pipeline ARN in the metadata output after you run the get-pipeline command. The pipeline ARN is constructed in this format:


    Sample pipeline ARN:


  8. Create or specify an IAM service role that grants Amazon CloudWatch Events permissions to invoke the target associated with your Amazon CloudWatch Events rule (in this case, the target is CodePipeline).

    • Choose Create a new role for this specific resource to create a service role that gives Amazon CloudWatch Events permissions to your start your pipeline executions when triggered.

    • Choose Use existing role to enter a service role that gives Amazon CloudWatch Events permissions to your start your pipeline executions when triggered.

  9. Review your rule setup to make sure it meets your requirements.

  10. Choose Configure details.

  11. On the Configure rule details page, enter a name and description for the rule, and then choose State to enable the rule.

  12. If you're satisfied with the rule, choose Create rule.