Associate an approval rule template with a repository - Amazon CodeCommit
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Associate an approval rule template with a repository

Approval rule templates are created in a specific Amazon Web Services Region, but they do not affect any repositores in that Amazon Web Services Region until they are associated. To apply a template to one or more repositories, you must associate the template with the repository or repositories. You can apply a single template to multiple repositories in an Amazon Web Services Region. This helps you automate and standardize the development workflow in your repositories by creating consistent conditions for approving and merging pull requests.

You can only associate an approval rule template with repositories in the Amazon Web Services Region where the approval rule template was created.

For more information about managed policies and permissions for approval rule templates, see Permissions for actions on approval rule templates and Amazon managed policies for CodeCommit.

Associate an approval rule template (console)

You might have associated repositories with an approval rule template when you created it. (That step is optional.) You can add or remove associations by editing the template.

To associate an approval rule template with repositories

  1. Open the CodeCommit console at https://console.www.amazonaws.cn/codesuite/codecommit/home.

  2. Choose Approval rule templates. Choose the template, and then choose Edit.

  3. In Associated Repositories, choose the repositories from the Repositories list. Each associated repository appears under the list box.

  4. Choose Save. Approval rules are now applied to any pull requests created in those associated repositories.

Associate an approval rule template (Amazon CLI)

You can use the Amazon CLI to associate an approval rule template with one or more repositories.

To associate a template with a single repository

  1. At the terminal or command line, run the associate-approval-rule-template-with-repository command, specifying:

    • The name of the approval rule template you want to associate with a repository.

    • The name of the repository to be associated with the approval rule template.

    For example, to associate an approval rule template named 2-approver-rule-for-main with a repository named MyDemoRepo:

    aws codecommit associate-approval-rule-template-with-repository --repository-name MyDemoRepo --approval-rule-template-name 2-approver-rule-for-main
  2. If successful, this command returns nothing.

To associate a template with multiple repositories

  1. At the terminal or command line, run the batch-associate-approval-rule-template-with-repositories command, specifying:

    • The name of the approval rule template you want to associate with a repository.

    • The names of the repositories to be associated with the approval rule template.

    For example, to associate an approval rule template named 2-approver-rule-for-main with a repository named MyDemoRepo and MyOtherDemoRepo:

    aws codecommit batch-associate-approval-rule-template-with-repositories --repository-names "MyDemoRepo", "MyOtherDemoRepo" --approval-rule-template-name 2-approver-rule-for-main
  2. If successful, this command returns output similar to the following:

    { "associatedRepositoryNames": [ "MyDemoRepo", "MyOtherDemoRepo" ], "errors": [] }