Reviewer Ug
Reviewer Ug
Reviewer Ug
User Guide
Amazon CodeGuru Reviewer User Guide
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not
Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or
discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may
or may not be affiliated with, connected to, or sponsored by Amazon.
Amazon CodeGuru Reviewer User Guide
Table of Contents
What is CodeGuru Reviewer? ............................................................................................................... 1
What kind of recommendations does CodeGuru Reviewer provide? ................................................... 1
What languages and repositories can I use with CodeGuru Reviewer? ................................................ 1
Accessing CodeGuru Reviewer ...................................................................................................... 2
................................................................................................................................................ 2
How CodeGuru Reviewer works ............................................................................................................ 3
Setting up ......................................................................................................................................... 4
Sign up for AWS ........................................................................................................................ 4
Configure IAM permissions .......................................................................................................... 4
Install or upgrade and then configure the AWS CLI ......................................................................... 5
Create a repository ..................................................................................................................... 5
Getting started .................................................................................................................................. 7
Step 1: Get set up ...................................................................................................................... 7
Step 2: Associate a repository ...................................................................................................... 7
Step 3: Get recommendations ...................................................................................................... 7
About repository analysis and pull request scans .................................................................... 8
Step 4: Provide feedback ............................................................................................................ 9
Provide feedback using the CodeGuru Reviewer console .......................................................... 9
Provide feedback using pull request comments ...................................................................... 9
Provide feedback using the CLI .......................................................................................... 10
Tutorial: monitor source code in GitHub .............................................................................................. 11
Step 1: Fork the repository ........................................................................................................ 11
Step 2: Associate the forked repository ....................................................................................... 11
Step 3: Push a change to the code ............................................................................................. 12
Step 4: Create a pull request ..................................................................................................... 13
Step 5: Review recommendations ............................................................................................... 13
Step 6: Clean up ...................................................................................................................... 14
Working with repository associations ................................................................................................. 15
Create a CodeCommit repository association .............................................................................. 16
Create an CodeCommit repository association (console) ........................................................ 16
Create a CodeCommit repository association (CodeCommit console) ....................................... 17
Create a CodeCommit repository association (AWS CLI) ......................................................... 17
Create a CodeCommit repository association (AWS SDKs) ...................................................... 19
Create a Bitbucket repository association ................................................................................... 19
Create an AWS CodeCommit repository association (console) ................................................. 19
Create a Bitbucket repository association (AWS CLI) .............................................................. 20
Create a Bitbucket repository association (AWS SDKs) ........................................................... 22
Create a GitHub or GitHub Enterprise Cloud repository association ................................................ 22
Create a GitHub Enterprise Server repository association .............................................................. 23
GitHub Enterprise Server prerequisites ................................................................................ 24
Create a GitHub Enterprise Server repository association (console) .......................................... 24
Create a GitHub Enterprise Server repository association (AWS CLI) ......................................... 26
Create a GitHub Enterprise Server repository association (AWS SDKs) ...................................... 27
View all repository associations .................................................................................................. 27
View all associated repositories (console) ............................................................................. 27
View all repository associations (AWS CLI) ........................................................................... 27
Disassociate a repository ........................................................................................................... 28
Disassociate a repository (console) ...................................................................................... 29
Disassociate a repository (AWS CLI) .................................................................................... 29
Encrypting a repository association ............................................................................................ 30
Encrypt an associated repository using a AWS KMS key ......................................................... 31
Update how a repository association is encrypted ................................................................ 31
Tagging a repository association ................................................................................................ 32
Add a tag to an associated repository ................................................................................. 32
iii
Amazon CodeGuru Reviewer User Guide
iv
Amazon CodeGuru Reviewer User Guide
CodeGuru Reviewer quotas for creating, deploying, and managing an API ........................................ 93
Troubleshooting ............................................................................................................................... 94
Where can I check the status of a repository association? .............................................................. 94
Where can I check the status of a code review? ............................................................................ 94
Where can I check the status of a third-party source provider connection? ....................................... 95
My repository is in an associated state. Why don't I see recommendations? ...................................... 95
Why did my association fail? ...................................................................................................... 95
Why did my code review fail? .................................................................................................... 95
What if I disagree with the recommendation? .............................................................................. 96
How do I suppress a recommendation? ....................................................................................... 96
The repository status has been associating for more than 5 minutes. What should I do? ..................... 96
The code review status has been Pending for more than 15 minutes. What should I do? ..................... 96
How do you access a repository if its owner is no longer available? ................................................. 97
Can I use the same AWS CodeStar connection to access repositories in two different accounts? ............ 97
I'm trying to connect to my third-party repositories. What is the difference between an app
installation and a connection? Which one can be used to adjust permissions? ................................... 97
How do I know if CodeGuru Reviewer used my aws-codeguru-reviewer.yml file in a code review? ......... 97
Why didn't my costs decrease when I used an aws-codeguru-reviewer.yml file? ................................. 99
Document history ........................................................................................................................... 100
AWS glossary ................................................................................................................................. 103
v
Amazon CodeGuru Reviewer User Guide
What kind of recommendations
does CodeGuru Reviewer provide?
By proactively detecting code defects, CodeGuru Reviewer can provide guidelines for addressing
them and implementing best practices to improve the overall quality and maintainability of your
code base during the code review stage. For more information, see How Amazon CodeGuru Reviewer
works (p. 3).
CodeGuru Reviewer also integrates with AWS Secrets Manager to use a secrets detector that finds
unprotected secrets in your code. For more information, see Secrets detection (p. 60).
• AWS CodeCommit
• Bitbucket
• GitHub
• GitHub Enterprise Cloud
• GitHub Enterprise Server
• Amazon S3
If you use any of these source providers, you can integrate with CodeGuru Reviewer with just a few steps.
After you associate a repository with CodeGuru Reviewer, you can interact with recommendations in the
CodeGuru Reviewer console. For pull request code reviews, you can also see recommendations directly
from inside pull requests in your repository context.
1
Amazon CodeGuru Reviewer User Guide
Accessing CodeGuru Reviewer
2
Amazon CodeGuru Reviewer User Guide
You can associate CodeGuru Reviewer with a repository to allow CodeGuru Reviewer to provide
recommendations. After you associate a repository with CodeGuru Reviewer, CodeGuru Reviewer
automatically analyzes pull requests that you make, and you can choose to run repository analyses on
the code in your branch to analyze all the code at any time.
If you want to suppress recommendations from CodeGuru Reviewer, you can create and add to the root
directory of your repository an aws-codeguru-reviewer.yml file that lists files and directories to
exclude from analysis. For more information, see Suppress recommendations (p. 43).
You can view recommendations from pull request and repository analysis scans directly in the CodeGuru
Reviewer console. You can also view recommendations from pull requests as pull request comments in
your repository source provider. These recommendations address instances in which the code doesn't
adhere to AWS SDK best practices, operations on concurrent data structures might not be thread safe, or
resource closure might not be handled properly, among other things.
Developers can decide how to incorporate the recommendations from CodeGuru Reviewer and provide
feedback (p. 9) to CodeGuru Reviewer about whether the recommendations were useful. This helps
your team ensure code quality and improve their code practices in an organic, interactive way. At the
same time, it improves the quality of recommendations CodeGuru Reviewer provides for your code,
making CodeGuru Reviewer increasingly effective in future analyses.
3
Amazon CodeGuru Reviewer User Guide
Sign up for AWS
You should know the following about Amazon Web Services (AWS):
• When you sign up for AWS, your AWS account automatically has access to all services in AWS,
including CodeGuru Reviewer. However, you are charged only for the services that you use.
• With CodeGuru Reviewer, you pay for the size of each of your associated repositories measured in lines
of code. For more information, see Amazon CodeGuru pricing.
Note
You can suppress recommendations from CodeGuru Reviewer, which reduces the number
of lines of code analyzed and, by extension, might reduce costs. For more information, see
Suppress recommendations (p. 43).
Topics
• Sign up for AWS (p. 4)
• Configure IAM permissions for Amazon CodeGuru Reviewer (p. 4)
• Install or upgrade and then configure the AWS CLI (p. 5)
• Create a repository for your source code (p. 5)
If you don't have an AWS account, you can use the following procedure to create one. If you are a new
Amazon CodeGuru Reviewer customer, you can sign up for a 90-day free trial.
1. Open https://portal.aws.amazon.com/billing/signup.
2. Follow the online instructions.
Part of the sign-up procedure involves receiving a phone call and entering a verification code on the
phone keypad.
4
Amazon CodeGuru Reviewer User Guide
Install or upgrade and then configure the AWS CLI
We strongly recommend that you not use the root user for everyday tasks, even the administrative
ones. Instead, create an IAM user with the least privileges needed. Then securely lock away the root
user credentials and use them to perform only a few account and service management tasks. For more
information, see Create individual IAM users in the AWS Identity and Access Management User Guide.
See the following topics for information about permissions required for CodeGuru Reviewer and how to
add them.
If you have an older version of the AWS CLI installed, we recommend you upgrade it so the CodeGuru
Reviewer commands are available. To check the version, use the aws --version command.
1. Follow the instructions in Installing the AWS Command Line Interface to install or upgrade the AWS
CLI.
2. To configure the AWS CLI, see Configuring the AWS Command Line Interface and Managing Access
Keys for IAM Users.
Important
When you configure the AWS CLI, you are prompted to specify an AWS Region. Choose one
of the supported Regions listed in Region and Endpoints in the AWS General Reference.
3. To verify the installation or upgrade, call the following command from the AWS CLI.
If you want to suppress recommendations from CodeGuru Reviewer, you can create and add to the root
directory of your repository an aws-codeguru-reviewer.yml file that lists files and directories to
exclude from analysis. For more information, see Suppress recommendations (p. 43).
5
Amazon CodeGuru Reviewer User Guide
Create a repository
After you know the repository type and the name of your repository, you need to create a repository
association. For GitHub repositories, you can create a repository association using only the CodeGuru
Reviewer console. For the other supported repository types, you can use the console, AWS CLI, or
Amazon CodeGuru Reviewer SDK to create a repository association. For more information, see Working
with repository associations in Amazon CodeGuru Reviewer (p. 15).
6
Amazon CodeGuru Reviewer User Guide
Step 1: Get set up
Topics
• Step 1: Get set up (p. 7)
• Step 2: Associate a repository (p. 7)
• Step 3: Get recommendations (p. 7)
• Step 4: Provide feedback (p. 9)
7
Amazon CodeGuru Reviewer User Guide
About repository analysis and pull request scans
defects in code that are difficult for developers to find. After a code review is successfully completed on
a repository analysis or pull request, you can view recommendations. You can then choose whether to
incorporate the recommendations, and you can provide feedback about whether the recommendations
were helpful.
Note
We recommend that you use both CodeGuru Reviewer and traditional peer review processes
during the code review stage. Using a combination of code review processes helps to identify
more issues before they reach production.
Type of code review Is the review automatic Where can I see What code is reviewed?
after I associate the recommendations?
repository?
Full repository analysis Your first full repository In the CodeGuru All the code in the
analysis is done Reviewer console, or by branch is reviewed.
automatically when using the AWS CLI or
you associate your AWS SDK.
repository. After that,
you must request a
repository analysis in
the CodeGuru Reviewer
console or by using the
AWS CLI or AWS SDK.
Incremental code Yes. After associating In the CodeGuru The code that is
review the repository, every Reviewer console, changed in the pull
time you do a pull in the AWS CLI or request is reviewed.
request there is a code AWS SDK, or in pull
review. request comments in
the repository source
provider.
GitHub Actions code Yes. After enabling In the GitHub Security The code that is
review in a CI/CD CodeGuru Reviewer on tab. changed in the push,
workflow your GitHub repository, pull, or scheduled
for every push, pull, or repository scan.
scheduled repository
scan there is a code
review.
8
Amazon CodeGuru Reviewer User Guide
Step 4: Provide feedback
Your feedback and comments are shared with CodeGuru Reviewer. This can help CodeGuru Reviewer
to improve its models and become more helpful to you and others in the future. When you
provide feedback, your code is not shared. For more information, see Captured data in CodeGuru
Reviewer (p. 64).
Note
The source code reviewed by CodeGuru Reviewer is not stored. For more information, see the
section called “Captured data” (p. 64).
Topics
• Provide feedback using the CodeGuru Reviewer console (p. 9)
• Provide feedback using pull request comments (p. 9)
• Provide feedback using the CLI (p. 10)
9
Amazon CodeGuru Reviewer User Guide
Provide feedback using the CLI
To view the feedback that you have submitted, call DescribeRecommendationFeedback using the
RecommendationId. To view feedback from all users, call ListRecommendationFeedback by using a
filter on RecommendationIds and UserIds. For more information, see the Amazon CodeGuru Reviewer
API Reference.
10
Amazon CodeGuru Reviewer User Guide
Step 1: Fork the repository
You work with an actual suboptimal example application in a GitHub repository as a test case. After you
associate the repository with CodeGuru Reviewer, you create a code change and submit a pull request
that triggers program analysis.
Because the example application contains intentional inefficiencies, CodeGuru Reviewer creates
recommendations about how to make it better. You learn how to review the recommendations and then
how to provide feedback about them. Customer feedback from code reviews helps improve CodeGuru
Reviewer recommendations over time.
• This tutorial creates code reviews that might result in charges to your AWS account. For more
information, see Amazon CodeGuru Pricing.
• Do not use the example code in production. It's intentionally problematic and intended for
demonstration purposes only.
11
Amazon CodeGuru Reviewer User Guide
Step 3: Push a change to the code
4. To allow CodeGuru Reviewer to access your account, choose Authorize aws-codesuite. If prompted,
confirm your GitHub password.
5. Select the amazon-codeguru-reviewer-sample-app repository, and then choose Associate.
CodeGuru Reviewer is now associated with the repository and listening for pull requests.
1. Run the following Git command to clone the forked repository, replacing USER_ID with your actual
GitHub user ID.
Note
If you access your GitHub repositories using SSH, use the SSH URL instead of the HTTPS
URL shown in this step.
2. Check out a new branch using the following command.
cd amazon-codeguru-reviewer-sample-app
git checkout -b dev
cp src/main/java/com/shipmentEvents/handlers/EventHandler.java src/main/java/com/
shipmentEvents/demo/
12
Amazon CodeGuru Reviewer User Guide
Step 4: Create a pull request
4. Choose Create pull request, then choose Create pull request again.
When the code review is complete and the recommendations appear in GitHub, you can provide
feedback on the recommendations using the thumbs up or thumbs down icon. Any positive or negative
feedback is used to help improve the performance of CodeGuru Reviewer so that recommendations get
better over time.
13
Amazon CodeGuru Reviewer User Guide
Step 6: Clean up
Step 6: Clean up
After you're finished with this tutorial, clean up your resources.
14
Amazon CodeGuru Reviewer User Guide
Immediately after you create the repository association, its status is Associating. A repository association
with this status is doing the following.
• Setting up pull request notifications. This is required for pull requests to initiate a CodeGuru Reviewer
review. For GitHub, GitHub Enterprise Server, and Bitbucket repositories, the notifications are
webhooks created in your repository to initiate CodeGuru Reviewer reviews. If you delete these
webhooks, reviews of code in your repository cannot be initiated.
• Setting up source code access. This is required for CodeGuru Reviewer to securely clone the code in
your repository.
When the pull request notifications, source code access, and creation of required permissions are
complete, the status changes to Associated. The association is now complete and CodeGuru Reviewer
performs its first full scan of the repository. You can later create incremental code reviews or full
repository analysis code reviews to get recommendations. For more information, see About full
repository analysis and incremental code reviews (p. 42).
CodeGuru Reviewer supports associations with repositories from the following source providers:
• AWS CodeCommit
• Bitbucket
• GitHub and GitHub Enterprise Cloud (These are listed together because you work with them identically
using CodeGuru Reviewer.)
• GitHub Enterprise Server
Note
The source code reviewed by CodeGuru Reviewer is not stored. For more information, see the
section called “Captured data” (p. 64).
Topics
• Create an AWS CodeCommit repository association in Amazon CodeGuru Reviewer (p. 16)
• Create a Bitbucket repository association in Amazon CodeGuru Reviewer (p. 19)
• Create a GitHub or GitHub Enterprise Cloud repository association in Amazon CodeGuru
Reviewer (p. 22)
• Create a GitHub Enterprise Server repository association in Amazon CodeGuru Reviewer (p. 23)
• View all repository associations in CodeGuru Reviewer (p. 27)
• Disassociate a repository in CodeGuru Reviewer (p. 28)
• Encrypting a repository association in Amazon CodeGuru Reviewer (p. 30)
15
Amazon CodeGuru Reviewer User Guide
Create a CodeCommit repository association
Topics
• Create a CodeCommit repository association (CodeGuru Reviewer console) (p. 16)
• Create a CodeCommit repository association (CodeCommit console) (p. 17)
• Create a CodeCommit repository association (AWS CLI) (p. 17)
• Create a CodeCommit repository association (AWS SDKs) (p. 19)
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For
information about finding the ARN of your key using the console, see Finding the key ID and
ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in
the AWS KMS console. For more information, see Creating keys in the AWS Key Management
Service Developer Guide.
7. In Run a repository analysis, specify information for your associated repository's first full scan. This
scan generates your repository's initial code review. For more information, see Get recommendations
using full repository analysis (p. 48).
16
Amazon CodeGuru Reviewer User Guide
Create a CodeCommit repository
association (CodeCommit console)
8. (Optional) Expand Tags to add one or more tags to your repository association. For more
information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 32).
17
Amazon CodeGuru Reviewer User Guide
Create a CodeCommit repository association (AWS CLI)
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews and in which your CodeCommit repository exists. To verify the Region, run the
following command at the command line or terminal and review the information for the default
name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the associate-repository command specifying the name of the CodeCommit repository you
want to associate.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029,
"Owner": "123456789012",
"State": "Associating",
"StateReason": "Pending Repository Association",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
}
}
4. When the associate-repository command succeeds, the status in the returned output is Associating.
When the association is complete, the status changes to Associated and you can create a pull
request or a repository analysis to get recommendations. You can check your repository association's
status using the describe-repository command with its Amazon Resource Name (ARN).
5. If successful, this command outputs a RepositoryAssociation object which shows its status.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029,
"Owner": "123456789012",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid"
}
}
18
Amazon CodeGuru Reviewer User Guide
Create a CodeCommit repository association (AWS SDKs)
Topics
• Create a Bitbucket repository association (console) (p. 19)
• Create a Bitbucket repository association (AWS CLI) (p. 20)
• Create a Bitbucket repository association (AWS SDKs) (p. 22)
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For
information about finding the ARN of your key using the console, see Finding the key ID and
ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in
the AWS KMS console. For more information, see Creating keys in the AWS Key Management
Service Developer Guide.
19
Amazon CodeGuru Reviewer User Guide
Create a Bitbucket repository association (AWS CLI)
8. In Run a repository analysis, specify information for your associated repository's first full scan. This
scan generates your repository's initial code review. For more information, see Get recommendations
using full repository analysis (p. 48).
9. (Optional) Expand Tags to add one or more tags to your repository association. For more
information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 32).
20
Amazon CodeGuru Reviewer User Guide
Create a Bitbucket repository association (AWS CLI)
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the associate-repository command specifying the owner (or user name) of your Bitbucket
account, the name of your repository, and the Amazon Resource Name (ARN) of your connection.
{
"RepositoryAssociation": {
"ProviderType": "Bitbucket",
"Name": "repository-name",
"LastUpdatedTimeStamp": 1595886585.96,
"AssociationId": "repository_association_uuid",
"CreatedTimeStamp": 1595886585.96,
"ConnectionArn": "arn:aws:codestar-connections:us-
west-2:123456789012:connection/connection_uuid",
"State": "Associating",
"StateReason": "Pending Repository Association",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
"Owner": "bitbucket-user-name"
}
}
4. When the associate-repository command succeeds, the status in the returned output is Associating.
When the association is complete, the status changes to Associated and you can create a pull
request or a repository analysis to get recommendations. You can check your repository association's
status using the describe-repository command with its Amazon Resource Name (ARN).
5. If successful, this command outputs a RepositoryAssociation object which shows its status.
{
"RepositoryAssociation": {
"ProviderType": "Bitbucket",
"Name": "repository-name",
"LastUpdatedTimeStamp": 1595886585.96,
"AssociationId": "repository_association_uuid",
"CreatedTimeStamp": 1595886585.96,
"ConnectionArn": "arn:aws:codestar-connections:us-
west-2:123456789012:connection/connection_uuid",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
21
Amazon CodeGuru Reviewer User Guide
Create a Bitbucket repository association (AWS SDKs)
"Owner": "bitbucket-user-name"
}
}
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For
information about finding the ARN of your key using the console, see Finding the key ID and
ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in
the AWS KMS console. For more information, see Creating keys in the AWS Key Management
Service Developer Guide.
22
Amazon CodeGuru Reviewer User Guide
Create a GitHub Enterprise Server repository association
8. In Run a repository analysis, specify information for your associated repository's first full scan. This
scan generates your repository's initial code review. For more information, see Get recommendations
using full repository analysis (p. 48).
9. (Optional) Expand Tags to add one or more tags to your repository association. For more
information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 32).
23
Amazon CodeGuru Reviewer User Guide
GitHub Enterprise Server prerequisites
Note
GitHub Enterprise Cloud repositories have a different procedure and different prerequisites. If
you're using GitHub Enterprise Cloud, follow this procedure instead.
Topics
• GitHub Enterprise Server repository association prerequisites (p. 24)
• Create a GitHub Enterprise Server repository association (console) (p. 24)
• Create a GitHub Enterprise Server repository association (AWS CLI) (p. 26)
• Create a GitHub Enterprise Server repository association (AWS SDKs) (p. 27)
Your GitHub Enterprise Server connection requires a host. The host represents your GitHub Enterprise
Server instance and is to what your GitHub Enterprise Server connection connects. A host can be an on-
premises server or a Virtual Private Cloud (VPC). For more information, see Amazon VPC configuration
for your host and Create a host in the AWS Developer Tools User Guide.
24
Amazon CodeGuru Reviewer User Guide
Create a GitHub Enterprise Server
repository association (console)
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For
information about finding the ARN of your key using the console, see Finding the key ID and
ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in
the AWS KMS console. For more information, see Creating keys in the AWS Key Management
Service Developer Guide.
8. In Run a repository analysis, specify information for your associated repository's first full scan. This
scan generates your repository's initial code review. For more information, see Get recommendations
using full repository analysis (p. 48).
9. (Optional) Expand Tags to add one or more tags to your repository association. For more
information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 32).
25
Amazon CodeGuru Reviewer User Guide
Create a GitHub Enterprise Server
repository association (AWS CLI)
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
2. Run the associate-repository command specifying the owner (or user name) of your GitHub
Enterprise Server account, the name of your repository, and the Amazon Resource Name (ARN) of
your connection.
{
"RepositoryAssociation": {
"ProviderType": "GitHubEnterpriseServer",
"Name": "repository-name",
"LastUpdatedTimeStamp": 1595966211.79,
"AssociationId": "repository-association-uuid",
"CreatedTimeStamp": 1595966211.79,
"ConnectionArn": "arn:aws:codestar-connections:us-
west-2:123456789012:connection/connection-uuid",
"State": "Associating",
"StateReason": "Pending Repository Association",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
east-2:123456789012:association:repository-association-uuid",
"Owner": "github-enterprise-server-user-name"
}
}
4. When the associate-repository command succeeds, the status in the returned output is Associating.
When the association is complete, the status changes to Associated and you can create a pull
request or a repository analysis to get recommendations. You can check your repository association's
status using the describe-repository command with its Amazon Resource Name (ARN).
5. If successful, this command outputs a RepositoryAssociation object which shows its status.
{
"RepositoryAssociation": {
"ProviderType": "GitHubEnterpriseServer",
"Name": "repository-name",
26
Amazon CodeGuru Reviewer User Guide
Create a GitHub Enterprise Server
repository association (AWS SDKs)
"LastUpdatedTimeStamp": 1595634764.029,
"AssociationId": "repository-association-uuid",
"CreatedTimeStamp": 1595634764.029,
"ConnectionArn": "arn:aws:codestar-connections:us-
west-2:123456789012:connection/connection_uuid"
"State": "Associated",
"StateReason": "Pull Request Notification configuration successful",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
"Owner": "github-enterprise-server-user-name"
}
}
Topics
• View all associated repositories in CodeGuru Reviewer (console) (p. 27)
• View all repository associations in CodeGuru Reviewer (AWS CLI) (p. 27)
27
Amazon CodeGuru Reviewer User Guide
Disassociate a repository
1. Make sure that you have configured the AWS CLI with the AWS Region that contains the repository
associations you want to view. Run the following command at the command line or terminal and
review or configure the Region for the AWS CLI.
aws configure
2. Run list-repository-associations.
{
"RepositoryAssociationSummaries": [
{
"LastUpdatedTimeStamp": 1595886609.616,
"Name": "test",
"AssociationId": "0bdac454-f6af-4adf-a625-de4db4b4bca1",
"Owner": "123456789012",
"State": "Associated",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:0bdac454-f6af-4adf-a625-de4db4b4bca1",
"ProviderType": "Bitbucket"
},
{
"LastUpdatedTimeStamp": 1595636969.035,
"Name": "CodeDeploy-CodePipeline-ECS-Tutorial",
"AssociationId": "eb2f7513-a132-47ad-81dc-bd718468ee1e",
"Owner": "123456789012",
"State": "Associated",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:eb2f7513-a132-47ad-81dc-bd718468ee1e",
"ProviderType": "CodeCommit"
},
{
"LastUpdatedTimeStamp": 1595634785.983,
"Name": "My-ecs-beta-repo",
"AssociationId": "d79156d7-6297-4b08-ba5a-f05b274e3518",
"Owner": "123456789012",
"State": "Associated",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:d79156d7-6297-4b08-ba5a-f05b274e3518",
"ProviderType": "CodeCommit"
}
]
}
28
Amazon CodeGuru Reviewer User Guide
Disassociate a repository (console)
Immediately after you choose to disassociate a repository, its status changes to Disassociating. If you
want to review code in your disassociated repository later, you can create a new repository association.
Note
Charges are not incurred for disassociated repositories.
Topics
• Disassociate a repository in CodeGuru Reviewer (console) (p. 29)
• Disassociate a repository in CodeGuru Reviewer (AWS CLI) (p. 29)
• Choose the radio button next to the repository you want to disassociate, then choose Disassociate
repository.
• Choose the association ID of the repository you want to disassociate. On its Repository page,
choose Disassociate repository. With this option, you can view details about your repository
before you disassociate it.
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the disassociate-repository command specifying the Amazon Resource Name (ARN) of your
associated repository.
29
Amazon CodeGuru Reviewer User Guide
Encrypting a repository association
"RepositoryAssociation": {
"AssociationId": "repository_association_uuid",
"Name": "repository-name",
"LastUpdatedTimeStamp": 1602119553.692,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1590712779.949,
"Owner": "123456789012",
"State": "Disassociating",
"AssociationArn": ""arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid"
}
}
4. When the disassociate-repository command completes, the repository is not associated with
Amazon CodeGuru Reviewer. You can check if your repository association successfully disassociated
using the describe-repository command with its Amazon Resource Name (ARN).
5. If successful, the repository association is deleted and the command correctly outputs the following:
You can encrypt an associated repository with a KMS key only when you create it. If you want to update
how an existing repository is encrypted, you must disassociate it and then recreate it with the encryption
you want. For more information, see Disassociate a repository in CodeGuru Reviewer (p. 28).
The encryption key (either an AWS owned and managed key, or a KMS key you create) encrypts the
associated repository and all of its code reviews. Each code review is a child of the associated repository
that contains the reviewed code.
If you encrypt an associated repository with a KMS key, then revoke access to that key by disabling it or
removing CodeGuru Reviewer's grant to AWS KMS using the AWS Identity and Access Management AWS
CLI or SDK, the following occurs:
To restore access to an associated repository that is encrypted with a disabled key, you can re-enable it.
For more information, see Enabling and disabling keys in the AWS Key Management Service Developer
Guide.
30
Amazon CodeGuru Reviewer User Guide
Encrypt an associated repository using a AWS KMS key
Note
Creation of an AWS KMS key results in charges to your AWS account. For more information, see
AWS Key Management Service pricing.
Topics
• Encrypt an associated repository using an AWS KMS key (p. 31)
• Update how a repository association is encrypted (p. 31)
1. Follow the steps in one of the following topics to create an association with your repository type:
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For
information about finding the ARN of your key using the console, see Finding the key ID and ARN
in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in the
AWS KMS console. For more information, see Creating keys in the AWS Key Management Service
Developer Guide.
5. Complete the rest of the steps to create your repository association.
31
Amazon CodeGuru Reviewer User Guide
Tagging a repository association
• A tag key (for example, CostCenter, Environment, Project, or Secret). Tag keys are case
sensitive.
• An optional field known as a tag value (for example, 111122223333, Production, or a team name).
Omitting the tag value is the same as using an empty string. Like tag keys, tag values are case
sensitive.
Together these are known as key-value pairs. For limits on the number of tags you can have on an
associated repository and restrictions on tag keys and values, see Tags (p. 92).
Tags help you identify and organize your AWS resources. Many AWS services support tagging, so you can
assign the same tag to resources from different services to indicate that the resources are related. For
example, you can assign the same tag to a CodeGuru Reviewer associated repository that you assign to
an AWS CodeBuild build project. For more information about using tags, see the Tagging best practices
whitepaper.
In CodeGuru Reviewer, you can use the CodeGuru Reviewer console, the AWS CLI, CodeGuru Reviewer
APIs, or AWS SDKs to add, manage, and remove tags for a repository association. In addition to
identifying, organizing, and tracking your repository association with tags, you can use tags in IAM
policies to help control who can view and interact with your repository association.
A repository association has a parent-child hierarchical relationship with code reviews because
a repository association contains all the code reviews inside it. Because of this, you can use
tags on repository associations to control access to the code reviews in it. For examples of tag-
based access policies, see Using tags to control access to Amazon CodeGuru Reviewer associated
repositories (p. 79).
Topics
• Add a tag to a CodeGuru Reviewer associated repository (p. 32)
• View tags for a CodeGuru Reviewer associated repository (p. 35)
• Add or update tags for a CodeGuru Reviewer associated repository (p. 37)
• Remove tags from a CodeGuru Reviewer associated repository (p. 39)
32
Amazon CodeGuru Reviewer User Guide
Add a tag to an associated repository
Important
Adding tags to an associated repository can impact access to that associated repository. Before
you add a tag to an associated repository, make sure to review any IAM policies that might
use tags to control access to resources such as associated repositories. For examples of tag-
based access policies, see Using tags to control access to Amazon CodeGuru Reviewer associated
repositories (p. 79).
Topics
• Add a tag to a CodeGuru Reviewer associated repository (console) (p. 33)
• Add a tag to a CodeGuru Reviewer associated repository (AWS CLI) (p. 34)
Topics
• Add a tag when you create a CodeGuru Reviewer associated repository (console) (p. 33)
• Add a tag to an existing CodeGuru Reviewer associated repository (console) (p. 33)
Add a tag when you create a CodeGuru Reviewer associated repository (console)
You can use the Amazon CodeGuru Reviewer console to add one or more tags when you create an
Amazon CodeGuru Reviewer associated repository.
1. Follow the steps in one of the following topics to create an association with your repository type:
33
Amazon CodeGuru Reviewer User Guide
Add a tag to an associated repository
• Choose the association ID of the associated repository where you want to view tags, then choose
Manage tags.
• Choose the radio button next to the associated repository where you want to view tags, then
choose Manage tags.
4. In Manage tags, for each tag you want to add:
Topics
• Add a tag when you create a CodeGuru Reviewer associated repository (AWS CLI) (p. 34)
• Add a tag to an existing CodeGuru Reviewer associated repository (AWS CLI) (p. 35)
Add a tag when you create a CodeGuru Reviewer associated repository (AWS
CLI)
You can use the AWS CLI to add tags to an associated repository when you create it.
Note
Because you cannot use the AWS CLI to create a GitHub repository, you cannot use the AWS
CLI to add tags to a GitHub repository when you create it. You can use the AWS CLI to add tags
to an existing GitHub repository using tag-resource. You can also add tags when you create a
GitHub repository association with the console.
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the associate-repository command specifying the tags you want to add with the --tags
parameter. Specify a tag's key and value using an equal symbol (for example, my-key=my-value).
For more information about how to use associate-repository to create an association with your
repository type, see one of the following:
34
Amazon CodeGuru Reviewer User Guide
View tags for an associated repository
The following example adds 3 tags when you create an AWS CodeCommit repository association.
3. If successful, this command outputs a RepositoryAssociation object that includes an array with
the 3 tags.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029,
"Owner": "123456789012",
"State": "Associating",
"StateReason": "Pending Repository Association",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
},
"Tags": {
"owner": "admin",
"status": "beta",
"value-1": "key-1",
}
}
• Follow the steps in Add or update tags for a CodeGuru Reviewer associated repository (AWS
CLI) (p. 38).
Topics
• View tags for an associated repository (console) (p. 36)
• View tags for a CodeGuru Reviewer associated repository (AWS CLI) (p. 36)
35
Amazon CodeGuru Reviewer User Guide
View tags for an associated repository
• Choose the association ID of the associated repository where you want to view tags, then look
under Tags.
• Choose the radio button next to the associated repository where you want to view tags, then
choose Manage tags.
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the describe-repository-association command and specify the Amazon Resource Name (ARN)
of the associated repository.
3. If successful, this command outputs a RepositoryAssociation object that includes an array with
its tags.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029,
"Owner": "123456789012",
"State": "Associating",
"StateReason": "Pending Repository Association",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid",
},
36
Amazon CodeGuru Reviewer User Guide
Add or update tags for an associated repository
"Tags": {
"owner": "admin",
"status": "beta",
"value-1": "key-1",
}
}
Topics
• Add or update tags for a CodeGuru Reviewer associated repository (console) (p. 37)
• Add or update tags for a CodeGuru Reviewer associated repository (AWS CLI) (p. 38)
• Choose the association ID of the associated repository where you want to view tags, then choose
Manage tags.
• Choose the radio button next to the associated repository where you want to view tags, then
choose Manage tags.
4. Enter new values in key and value to edit tags. Choose Remove next to a tag to remove it. Choose
Add new tag to add a new tag.
5. Choose Save changes when you are finished.
37
Amazon CodeGuru Reviewer User Guide
Add or update tags for an associated repository
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the tag-resource command. Use --resource-arn to specify the Amazon Resource Name
(ARN) of the associated repository that contains the tags you want to update or add. Use the --
tags argument to specify the tags you want to update or add. The following command specifies 3
tags. If one of the keys already exists, its value is updated. If not, a new key is added.
3. If successful, there is no output and no error. If you want to verify the tags were added correctly, use
the describe-repository-association command and use --association-arn to specify the ARN of
the associated repository.
The output is a RepositoryAssociation object that includes an array with the 3 added or
updated tags.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-repository-name",
"LastUpdatedTimeStamp": 1603493340.035,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1603493328.512,
"Owner": "123456789012",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid"
},
"Tags": {
"key3": "value3",
"key2": "value2",
"key1": "value1"
}
38
Amazon CodeGuru Reviewer User Guide
Remove tags from an associated repository
Topics
• Remove tags from a CodeGuru Reviewer associated repository (console) (p. 39)
• Remove tags from a CodeGuru Reviewer associated repository (AWS CLI) (p. 39)
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create
your code reviews. To verify the Region, run the following command at the command line or
terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the untag-resource command. Use --resource-arn to specify the Amazon Resource Name
(ARN) of the associated repository that contains the tags you want to update or add to. Use the --
tag-keys argument to specify the key of the tags you want to remove. The following command
removes 3 tags.
39
Amazon CodeGuru Reviewer User Guide
Remove tags from an associated repository
3. If successful, there is no output and no error. If you want to verify the tags were removed correctly,
use the describe-repository-association command and use --association-arn to specify the
ARN of the associated repository.
The output is a RepositoryAssociation object that includes an array that does not contain
the keys you removed. In the following output example, all tags were removed so the tags array is
empty.
{
"RepositoryAssociation": {
"AssociationId": "repository-association-uuid",
"Name": "my-repository-name",
"LastUpdatedTimeStamp": 1603493340.035,
"ProviderType": "CodeCommit",
"CreatedTimeStamp": 1603493328.512,
"Owner": "123456789012",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful",
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:repository-association-uuid"
},
"Tags": {}
}
40
Amazon CodeGuru Reviewer User Guide
When you create a code review, CodeGuru Reviewer reviews your code and provides recommendations
about how to improve the code. You can see these recommendations directly in the CodeGuru Reviewer
console Code reviews page. For incremental code reviews, you can also see these recommendations as
comments on a pull request.
If a repository contains Java and Python files, then CodeGuru Reviewer generates recommendations for
the language for which there are more files. For example, if there are five Java files and ten Python files
in an associated repository, then CodeGuru Reviewer generates recommendations for the Python code
and does not generate recommendations for the Java code. If the number of Java and Python files is the
same, then only Java recommendations are generated.
If you want to suppress recommendations from CodeGuru Reviewer, you can create and add to the root
directory of your repository an aws-codeguru-reviewer.yml file that lists files and directories to
exclude from analysis. For more information, see Suppress recommendations (p. 43).
You can do the following on the Code reviews page in the CodeGuru console:
Topics
• About full repository analysis and incremental code reviews (p. 42)
• Suppress recommendations from Amazon CodeGuru Reviewer (p. 43)
• Create code reviews in Amazon CodeGuru Reviewer (p. 47)
• View all code reviews (p. 52)
• View code review details (p. 53)
• View recommendations and provide feedback (p. 54)
41
Amazon CodeGuru Reviewer User Guide
About full repository analysis and incremental code reviews
• Incremental code reviews are created automatically when you create a pull request from your
repository context on an associated repository. These code reviews scan the changed code in a pull
request.
• Full repository analysis code reviews are done when you create a repository analysis code review in the
CodeGuru Reviewer console. These code reviews scan all the code in a specified branch.
Note
Your first full repository analysis is created for you when you associate your repository.
• Full repository analysis code reviews for CI/CD workflows scan all the source code in your CI/CD
workflow. For more information, see Create code reviews with GitHub Actions.
You can get recommendations in code reviews by using a full repository analysis or an incremental code
review. After you associate a repository, you can choose when to have an entire branch get a code review
at any time by using a repository analysis. Every pull request created on an associated repository also
receives a code review.
Type of code review Is the review automatic Where can I see What code is reviewed?
after I associate the recommendations?
repository?
Full repository analysis Your first full repository In the CodeGuru All the code in the
analysis is done Reviewer console, or by branch is reviewed.
automatically when using the AWS CLI or
you associate your AWS SDK.
repository. After that,
you must request a
repository analysis in
the CodeGuru Reviewer
console or by using the
AWS CLI or AWS SDK.
Incremental code Yes. After associating In the CodeGuru The code that is
review the repository, every Reviewer console, changed in the pull
time you do a pull in the AWS CLI or request is reviewed.
request there is a code AWS SDK, or in pull
review. request comments in
the repository source
provider.
GitHub Actions code Yes. After enabling In the GitHub Security The code that is
review in a CI/CD CodeGuru Reviewer on tab. changed in the push,
workflow your GitHub repository, pull, or scheduled
for every push, pull, or repository scan.
scheduled repository
scan there is a code
review.
42
Amazon CodeGuru Reviewer User Guide
Suppress recommendations
By excluding files or directories, your costs associated with CodeGuru Reviewer analyzing your repository
might also decrease. For more information, see Cost impact of suppressing recommendations (p. 47).
The following examples describe scenarios in which you might want to use an aws-codeguru-
reviewer.yml file to exclude files or directories.
• Your repository contains directories that should not be included in a code review, such as test,
generated, or module directories.
• Your repository is a large open-source repository and you do not want files about a feature or product
inside the repository to be analyzed.
Topics
• Structure of the aws-codeguru-reviewer.yml file (p. 43)
• Steps to suppress recommendations (p. 45)
• Cost impact of suppressing recommendations (p. 47)
• Error handling for the aws-codeguru-reviewer.yml file (p. 47)
43
Amazon CodeGuru Reviewer User Guide
Structure of the file
For more information about glob expressions, see glob (programming) in Wikipedia.
Replace the items under excludeFiles: with your own files and directories. For information about how
to exclude files and directories, see Example code for the aws-codeguru-reviewer.yml file (p. 44).
Note
Be sure to use relative paths for files and directories that you add to your aws-codeguru-
reviewer.yml file.
version: 1.0
excludeFiles:
- 'src/some-package/**'
- 'tst/**'
- 'src/some-*/**/*.json'
In the following example, CodeGuru Reviewer excludes from analysis anything in the resources
directory.
version: 1.0
excludeFiles:
- 'resources/*'
In the following example, CodeGuru Reviewer excludes from analysis all files under any directory named
configuration.
44
Amazon CodeGuru Reviewer User Guide
Steps to suppress recommendations
version: 1.0
excludeFiles:
- '**/configuration/*'
In the following example, CodeGuru Reviewer excludes from analysis any file with a .java extension.
version: 1.0
excludeFiles:
- '**/*.java'
To suppress recommendations
1. Create an aws-codeguru-reviewer.yml file. For more information, see Structure of the aws-
codeguru-reviewer.yml file (p. 43).
2. Add the aws-codeguru-reviewer.yml file to the root directory of the repository that you want
CodeGuru Reviewer to analyze.
3. For new repositories, associate the repository. After you associate the repository, CodeGuru Reviewer
automatically initiates a full repository analysis code review. For more information, see Working
with repository associations (p. 15).
4. For repositories that have already been associated, initiate either a full repository analysis code
review or an incremental code review. For more information, see Create code reviews (p. 47).
5. To confirm that CodeGuru Reviewer used your file for the code review, check the CodeGuru Reviewer
console.
a. Choose Code reviews. This page lists all code reviews performed.
b. Choose the code review that CodeGuru Reviewer just performed.
• If CodeGuru Reviewer used your file in the code review, then Success appears under
Analysis configuration file.
45
Amazon CodeGuru Reviewer User Guide
Steps to suppress recommendations
• If CodeGuru Reviewer found errors in your file, then Error appears under Analysis
configuration file and a message indicating the errors appears at the top of the page.
Also, Failed appears under Status, indicating that CodeGuru Reviewer did not perform a
code review.
Fix your aws-codeguru-reviewer.yml file based on the error messages and then
initiate a new full repository analysis. For more information, see Error handling for the aws-
codeguru-reviewer.yml file (p. 47).
• If CodeGuru Reviewer did not recognize your file name or find the file at the root directory
of your repository, then No file detected appears under Analysis configuration file. Your
file must be named aws-codeguru-reviewer.yml and must exist in the root directory of
your repository. Otherwise CodeGuru Reviewer cannot recognize that the file exists, use it in
code reviews, or return error messages about problems with the file.
Confirm the name and location of your file, make any needed changes, and then initiate a
new code review.
6. Check Recommendations to confirm that the recommendations match what you expect based on
the settings in your aws-codeguru-reviewer.yml file.
46
Amazon CodeGuru Reviewer User Guide
Cost impact of suppressing recommendations
If you receive an error message about the aws-codeguru-reviewer.yml file, CodeGuru Reviewer did
not analyze your repository and you are not charged. For more information about error messages, see
Error handling for the aws-codeguru-reviewer.yml file (p. 47).
• When you initiate a full repository analysis code review in the console, messages about any errors
appear in the CodeGuru Reviewer console.
• When you submit a pull request for the analysis configuration file, messages about any errors appear
as comments in the aws-codeguru-reviewer.yml file.
• When you initiate an incremental code review, messages about any errors appear in comments on the
changed lines of code in your pull request.
In these situations, CodeGuru Reviewer does not review any files or directories, and you are not charged
for the attempted analysis.
47
Amazon CodeGuru Reviewer User Guide
Get recommendations using full repository analysis
on a full repository analysis or incremental code review, you can view recommendations. You can then
choose whether to incorporate the recommendations, and you can provide feedback about whether the
recommendations were helpful.
If you want to suppress recommendations, you can add files and directories to an aws-codeguru-
reviewer.yml file for CodeGuru Reviewer to exclude from analysis. You can create this analysis
configuration file and add it to the root directory of your repository at any time. CodeGuru Reviewer uses
the file for both incremental code reviews and full repository analysis code reviews, or returns errors
indicating problems with the file. For more information, see Suppress recommendations (p. 43).
Note
We recommend that you use both CodeGuru Reviewer and traditional peer review processes
during the code review stage. Using a combination of code review processes helps to identify
more issues before they reach production.
There are three different kinds of code reviews that CodeGuru Reviewer can do to provide
recommendations.
• Incremental code reviews are created automatically when you create a pull request from your
repository context on an associated repository. These code reviews scan the changed code in a pull
request.
• Full repository analysis code reviews scan all the code in a specified branch in the CodeGuru Reviewer
console.
• Full repository analysis code reviews for CI/CD workflows scan all the source code in your CI/CD
workflow. For more information, see Create code reviews with GitHub Actions.
For more information on the difference between incremental code reviews and full repository analysis
code reviews, see About full repository analysis and incremental code reviews (p. 42).
Topics
• Get recommendations using full repository analysis (p. 48)
• Get recommendations using incremental code reviews (p. 49)
• Get recommendations using GitHub Actions (p. 50)
A window opens for you to specify the location of the source code you wish to scan.
3. On the Create full repository analysis page, choose the associated repository from the list, then
choose the branch you want reviewed.
48
Amazon CodeGuru Reviewer User Guide
Get recommendations using incremental code reviews
4. (Optional) If you want to, you can provide a name for your code review. If you don't, CodeGuru
Reviewer provides a name for you that you can modify.
5. (Optional) If you want to suppress recommendations, create an aws-codeguru-reviewer.yml
file and add it to the root directory of your repository. You can download a sample file to use
as a template from the Analysis configuration file section. For more information, see Suppress
recommendations (p. 43).
6. When you have specified the branch you want reviewed, choose Create full repository analysis.
To view the recommendations, navigate to the Code reviews page in the console and choose the name
of the code review to view the detailed code review page. If you do not see the code review right away,
try refreshing the page. For more information, see View code review details (p. 53).
If a repository contains Java and Python files, then CodeGuru Reviewer generates recommendations for
the language for which there are more files. For example, if there are five Java files and ten Python files
in an associated repository, then CodeGuru Reviewer generates recommendations for the Python code
and does not generate recommendations for the Java code. If the number of Java and Python files is the
same, then only Java recommendations are generated.
49
Amazon CodeGuru Reviewer User Guide
Get recommendations using GitHub Actions
To view the recommendations in the CodeGuru Reviewer console, navigate to the Code reviews page in
the console and choose the name of the code review to view the detailed code review page.
Topics
• Create code reviews with GitHub Actions (p. 50)
• Disassociate your CI/CD workflow (p. 51)
• GitHub Actions code review examples (p. 51)
1. Create an Amazon S3 bucket with the prefix codeguru-reviewer-* to upload your code and artifacts.
For information on creating a new Amazon S3 bucket, see Creating a bucket.
2. Sign into your GitHub account to complete the CI/CD integration process. Your repository must be
public or private if it's part of a GitHub organization in order for GitHub actions to work.
3. In order to run the CodeGuru Reviewer Action, you need to provide AWS credentials. We recommend
using aws-actions/configure-aws-credentials to configure your credentials for a job. For self-hosted
runners, the configure-aws-credentials action assumes the runner’s IAM credentials or role to
the CodeGuru Reviewer Action. Docker must be installed for self-hosted runners. For information on
installing Docker, see Get started with Docker.
For GitHub hosted runners, you can configure the credentials in GitHub Secrets.
The IAM user or IAM role should have the AmazonCodeGuruReviewerFullAccess policy enabled
and Amazon S3 Permissions (s3:PutObject, s3:ListBucket, s3:GetObject). For more
details on AWS credentials, see Configuration and credential file settings.
4. Add the CodeGuru Reviewer Action. The following code snippet provides an example showing how
you can enable your workflow, as supported by CodeGuru Reviewer.
50
Amazon CodeGuru Reviewer User Guide
Get recommendations using GitHub Actions
5. Run your workflow in GitHub to start the code analysis. When the build is complete, review your
recommendations in the GitHub Security tab.
If you want to stop CodeGuru Reviewer recommendations for your CI workflow, remove the codeguru
action script from your repository’s YML file. Then, choose Disassociate repository to remove the
repository association. On your next job run, CodeGuru Reviewer associates the repository again unless
you remove the codeguru action script from the YML file.
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Required
51
Amazon CodeGuru Reviewer User Guide
View all code reviews
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
To learn about the types of code reviews CodeGuru Reviewer performs and their recommendations, see
Recommendation types in CodeGuru Reviewer (p. 60).
52
Amazon CodeGuru Reviewer User Guide
Navigate to repositories and pull requests
Note
After 90 days have passed since a code review was done, you can't view that code review in the
Amazon CodeGuru Reviewer console. But you might be able to view the recommendations from
incremental code reviews in the repository source provider.
To view code reviews with the AWS CLI or the AWS SDK, call ListCodeReviews. You can filter using
ProviderType, RepositoryName, or State. For more information, see the Amazon CodeGuru
Reviewer API Reference.
Topics
• Information in code review details (p. 53)
• View code review details by using the AWS CLI (p. 54)
• Pending – CodeGuru Reviewer has received the incremental code review notification or the full
repository analysis request and a code review is scheduled. Make sure you maintain access permissions
53
Amazon CodeGuru Reviewer User Guide
View code review details by using the AWS CLI
to your source branch while CodeGuru Reviewer processes the request. If the code review is for a pull
request, keep the pull request open.
• Completed – CodeGuru Reviewer successfully finished reviewing the source code.
• Failed – The code review has failed to finish reviewing the source code. This could be because of a
problem with source code access permissions or a transient exception that occurred:
• If the problem is due to source code access permissions, the easiest way to fix it is to disassociate the
repository and then associate the repository again. If the error persists, contact AWS Support.
• If the problem is due to a transient exception, the code review request is retried.
• If the problem is due to an analysis configuration file error, then review the errors with the file, fix
the file, and initiate an incremental code review or a full repository analysis. For more information,
see Error handling for the aws-codeguru-reviewer.yml file (p. 47).
When you retry the operation, be sure to keep relevant incremental code reviews open and the source
branch available while CodeGuru Reviewer processes the request.
You can view code review details by choosing the name of the code review.
If you have the code review ARN, you can call DescribeCodeReview. Alternatively, you can call
ListCodeReviews and filter using ProviderType and RepositoryName.
Providing feedback can improve the quality of recommendations Amazon CodeGuru Reviewer provides
for your code, making CodeGuru Reviewer increasingly effective in later analyses.
You can also view recommendations and provide feedback in incremental code reviews directly in your
repository source provider, or by using the CLI. For more information, see Step 4: Provide feedback (p. 9).
Your feedback is used to improve CodeGuru Reviewer through model-tuning efforts that will help make
CodeGuru Reviewer recommendations more useful to you and others.
54
Amazon CodeGuru Reviewer User Guide
Get recommendations using GitHub Actions
You can enable security and code quality recommendations with GitHub Actions by making the following
changes to your workflow. If your repository has files in both Java and Python, then CodeGuru Reviewer
will provide recommendations for the language that has more files. An example workflow file could be
.github/workflows/build.yml.
Topics
• Create code reviews with GitHub Actions (p. 50)
• Disassociate your CI/CD workflow (p. 51)
• GitHub Actions code review examples (p. 51)
1. Create an Amazon S3 bucket with the prefix codeguru-reviewer-* to upload your code and artifacts.
For information on creating a new Amazon S3 bucket, see Creating a bucket.
2. Sign into your GitHub account to complete the CI/CD integration process. Your repository must be
public or private if it's part of a GitHub organization in order for GitHub actions to work.
3. In order to run the CodeGuru Reviewer Action, you need to provide AWS credentials. We recommend
using aws-actions/configure-aws-credentials to configure your credentials for a job. For self-hosted
runners, the configure-aws-credentials action assumes the runner’s IAM credentials or role to
the CodeGuru Reviewer Action. Docker must be installed for self-hosted runners. For information on
installing Docker, see Get started with Docker.
For GitHub hosted runners, you can configure the credentials in GitHub Secrets.
The IAM user or IAM role should have the AmazonCodeGuruReviewerFullAccess policy enabled
and Amazon S3 Permissions (s3:PutObject, s3:ListBucket, s3:GetObject). For more
details on AWS credentials, see Configuration and credential file settings.
4. Add the CodeGuru Reviewer Action. The following code snippet provides an example showing how
you can enable your workflow, as supported by CodeGuru Reviewer.
55
Amazon CodeGuru Reviewer User Guide
Disassociate your CI/CD workflow
If you want to stop CodeGuru Reviewer recommendations for your CI workflow, remove the codeguru
action script from your repository’s YML file. Then, choose Disassociate repository to remove the
repository association. On your next job run, CodeGuru Reviewer associates the repository again unless
you remove the codeguru action script from the YML file.
steps:
- name: Checkout repository
56
Amazon CodeGuru Reviewer User Guide
GitHub Actions code review examples
uses: actions/checkout@v2
with:
fetch-depth: 0 # Required
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
57
Amazon CodeGuru Reviewer User Guide
Products and services that are integrated with Amazon CodeGuru Reviewer
AWS CloudTrail CloudTrail captures AWS API calls and related
events made by or on behalf of an AWS account
and delivers log files to an Amazon S3 bucket
that you specify. You can configure CloudTrail to
capture API calls from the CodeGuru Reviewer
console, CodeGuru Reviewer commands from the
AWS Command Line Interface (AWS CLI), and from
the CodeGuru Reviewer API.
58
Amazon CodeGuru Reviewer User Guide
59
Amazon CodeGuru Reviewer User Guide
Secrets detection
If you don't agree with a recommendation, you can provide feedback (p. 9) in the CodeGuru Reviewer
console or by commenting on the code in the pull requests. Any positive or negative feedback can be
used to help improve the performance of CodeGuru Reviewer so that recommendations get better over
time.
If you want to suppress recommendations from CodeGuru Reviewer, you can create and add to the root
directory of your repository an aws-codeguru-reviewer.yml file that lists files and directories to
exclude from analysis. For more information, see Suppress recommendations (p. 43).
The following content describes the secrets detection functionality of CodeGuru Reviewer. For
information about the other recommendation types and the detectors that CodeGuru Reviewer uses, see
the Amazon CodeGuru Reviewer Detector Library.
Secrets detection
CodeGuru Reviewer integrates with AWS Secrets Manager to use a secrets detector that finds
unprotected secrets in your code. Secrets detection is automatic, so you don't need to turn it on.
The secrets detector searches for hardcoded passwords, database connection strings, user names,
and more. When an unprotected secret is found during a code review, CodeGuru Reviewer generates
a recommendation and displays it with your code reviews. The recommendation tells you about the
unprotected secret. To immediately protect that secret, choose Protect your credential in the code
review. This opens the Secrets Manager console to protect and manage the secret. For more information,
see Move hardcoded secrets to AWS Secrets Manager in the AWS Secrets Manager User Guide and View
recommendations and provide feedback (p. 54).
Topics
• Secrets detection supported file types (p. 60)
• Types of secrets detected by CodeGuru Reviewer (p. 61)
60
Amazon CodeGuru Reviewer User Guide
Types of secrets detected
61
Amazon CodeGuru Reviewer User Guide
Types of secrets detected
Slack • Client ID
• Client Secret
62
Amazon CodeGuru Reviewer User Guide
Data protection
Security is a shared responsibility between AWS and you. The shared responsibility model describes this
as security of the cloud and security in the cloud:
• Security of the cloud – AWS is responsible for protecting the infrastructure that runs AWS services in
the AWS Cloud. AWS also provides you with services that you can use securely. Third-party auditors
regularly test and verify the effectiveness of our security as part of the AWS Compliance Programs. To
learn about the compliance programs that apply to Amazon CodeGuru Reviewer, see AWS Services in
Scope by Compliance Program.
• Security in the cloud – Your responsibility is determined by the AWS service that you use. You are also
responsible for other factors including the sensitivity of your data, your company's requirements, and
applicable laws and regulations.
This documentation helps you understand how to apply the shared responsibility model when using
CodeGuru Reviewer. The following topics show you how to configure CodeGuru Reviewer to meet your
security and compliance objectives.
Topics
• Data protection for CodeGuru Reviewer (p. 63)
• Identity and access management in CodeGuru Reviewer (p. 65)
• Logging and monitoring in CodeGuru Reviewer (p. 85)
• Compliance validation for CodeGuru Reviewer (p. 89)
• CodeGuru Reviewer and interface VPC endpoints (AWS PrivateLink) (p. 90)
• Infrastructure security in CodeGuru Reviewer (p. 91)
For data protection purposes, we recommend that you protect AWS account credentials and set up
individual user accounts with AWS Identity and Access Management (IAM). That way each user is given
only the permissions necessary to fulfill their job duties. We also recommend that you secure your data
in the following ways:
63
Amazon CodeGuru Reviewer User Guide
Captured data
• Use AWS encryption solutions, along with all default security controls within AWS services.
• Use advanced managed security services such as Amazon Macie, which assists in discovering and
securing personal data that is stored in Amazon S3.
• If you require FIPS 140-2 validated cryptographic modules when accessing AWS through a command
line interface or an API, use a FIPS endpoint. For more information about the available FIPS endpoints,
see Federal Information Processing Standard (FIPS) 140-2.
We strongly recommend that you never put confidential or sensitive information, such as your
customers' email addresses, into tags or free-form fields such as a Name field. This includes when
you work with CodeGuru Reviewer or other AWS services using the console, API, AWS CLI, or AWS
SDKs. Any data that you enter into tags or free-form fields used for names may be used for billing or
diagnostic logs. If you provide a URL to an external server, we strongly recommend that you do not
include credentials information in the URL to validate your request to that server.
Topics
• Captured data in CodeGuru Reviewer (p. 64)
• Data retention in CodeGuru Reviewer (p. 64)
• Data encryption in CodeGuru Reviewer (p. 64)
• Traffic privacy (p. 65)
After an associated repository is disassociated, you can no longer see its recommendations.
Recommendations and pull request metadata (for example, the branch name) are retained for one year,
and then deleted. Feedback provided to help CodeGuru Reviewer improve future recommendations is
retained forever.
64
Amazon CodeGuru Reviewer User Guide
Traffic privacy
• Encryption of data at rest – Data collected by CodeGuru Reviewer is stored using Amazon Simple
Storage Service and Amazon DynamoDB. The data is encrypted using their data-at-rest encryption
capabilities.
• Encryption of data in transit – All communication between customers and CodeGuru Reviewer and
between CodeGuru Reviewer and its downstream dependencies is protected using TLS connections
that are signed using the Signature Version 4 signing process. All CodeGuru Reviewer endpoints use
SHA-256 certificates that are managed by AWS Certificate Manager Private Certificate Authority. For
more information, see Signature Version 4 Signing Process and What is ACM PCA.
• Associated repository and code review encryption – Associated repositories and code reviews
are encrypted by default using a key that AWS owns and manages. If you do not want to use a key
managed by AWS, you must create an AWS Key Management Service key. For more information, see
Creating keys and AWS Key Management Service concepts in the AWS Key Management Service User
Guide and Encrypting a repository association in Amazon CodeGuru Reviewer (p. 30).
Traffic privacy
You can improve the security of associated repositories and code reviews by configuring CodeGuru
Reviewer to use an interface VPC endpoint. To do this, you do not need an internet gateway, NAT
device, or virtual private gateway. It also is not required to configure AWS PrivateLink, though it is
recommended. For more information, see CodeGuru Reviewer and interface VPC endpoints (AWS
PrivateLink) (p. 90). For more information about AWS PrivateLink and VPC endpoints, see AWS
PrivateLink and Accessing AWS services through PrivateLink.
Topics
• Audience in CodeGuru Reviewer (p. 65)
• Authenticating with identities in CodeGuru Reviewer (p. 66)
• Managing access using policies (p. 68)
• Overview of managing access permissions to your CodeGuru Reviewer resources (p. 69)
• Using identity-based policies for CodeGuru Reviewer (p. 71)
• Using tags to control access to Amazon CodeGuru Reviewer associated repositories (p. 79)
• Amazon CodeGuru Reviewer permissions reference (p. 81)
• Troubleshooting CodeGuru Reviewer identity and access (p. 83)
Service user – If you use the CodeGuru Reviewer service to do your job, then your administrator provides
you with the credentials and permissions that you need. As you use more CodeGuru Reviewer features to
65
Amazon CodeGuru Reviewer User Guide
Authenticating with identities in CodeGuru Reviewer
do your work, you might need additional permissions. Understanding how access is managed can help
you request the right permissions from your administrator. If you cannot access a feature in CodeGuru
Reviewer, see Troubleshooting CodeGuru Reviewer identity and access (p. 83).
Service administrator – If you're in charge of CodeGuru Reviewer resources at your company, you
probably have full access to CodeGuru Reviewer. It's your job to determine which CodeGuru Reviewer
features and resources your employees should access. You must then submit requests to your IAM
administrator to change the permissions of your service users. Review the information on this page
to understand the basic concepts of IAM. To learn more about how your company can use IAM with
CodeGuru Reviewer, see Overview of managing access permissions to your CodeGuru Reviewer
resources (p. 69).
IAM administrator – If you're an IAM administrator, you might want to learn details about how you can
write policies to manage access to CodeGuru Reviewer. To view example CodeGuru Reviewer identity-
based policies that you can use in IAM, see Customer managed policy examples (p. 77).
You must be authenticated (signed in to AWS) as the AWS account root user, an IAM user, or by assuming
an IAM role. You can also use your company's single sign-on authentication or even sign in using Google
or Facebook. In these cases, your administrator previously set up identity federation using IAM roles.
When you access AWS using credentials from another company, you are assuming a role indirectly.
To sign in directly to the AWS Management Console, use your password with your root user email
address or your IAM user name. You can access AWS programmatically using your root user or IAM
users access keys. AWS provides SDK and command line tools to cryptographically sign your request
using your credentials. If you don't use AWS tools, you must sign the request yourself. Do this using
Signature Version 4, a protocol for authenticating inbound API requests. For more information about
authenticating requests, see Signature Version 4 signing process in the AWS General Reference.
Regardless of the authentication method that you use, you might also be required to provide additional
security information. For example, AWS recommends that you use multi-factor authentication (MFA) to
increase the security of your account. To learn more, see Using multi-factor authentication (MFA) in AWS
in the IAM User Guide.
66
Amazon CodeGuru Reviewer User Guide
Authenticating with identities in CodeGuru Reviewer
An IAM group is an identity that specifies a collection of IAM users. You can't sign in as a group. You
can use groups to specify permissions for multiple users at a time. Groups make permissions easier to
manage for large sets of users. For example, you could have a group named IAMAdmins and give that
group permissions to administer IAM resources.
Users are different from roles. A user is uniquely associated with one person or application, but a role
is intended to be assumable by anyone who needs it. Users have permanent long-term credentials, but
roles provide temporary credentials. To learn more, see When to create an IAM user (instead of a role) in
the IAM User Guide.
IAM roles
An IAM role is an identity within your AWS account that has specific permissions. It is similar to an IAM
user, but is not associated with a specific person. You can temporarily assume an IAM role in the AWS
Management Console by switching roles. You can assume a role by calling an AWS CLI or AWS API
operation or by using a custom URL. For more information about methods for using roles, see Using IAM
roles in the IAM User Guide.
IAM roles with temporary credentials are useful in the following situations:
• Temporary IAM user permissions – An IAM user can assume an IAM role to temporarily take on
different permissions for a specific task.
• Federated user access – Instead of creating an IAM user, you can use existing identities from AWS
Directory Service, your enterprise user directory, or a web identity provider. These are known as
federated users. AWS assigns a role to a federated user when access is requested through an identity
provider. For more information about federated users, see Federated users and roles in the IAM User
Guide.
• Cross-account access – You can use an IAM role to allow someone (a trusted principal) in a different
account to access resources in your account. Roles are the primary way to grant cross-account access.
However, with some AWS services, you can attach a policy directly to a resource (instead of using a role
as a proxy). To learn the difference between roles and resource-based policies for cross-account access,
see How IAM roles differ from resource-based policies in the IAM User Guide.
• Cross-service access – Some AWS services use features in other AWS services. For example, when you
make a call in a service, it's common for that service to run applications in Amazon EC2 or store objects
in Amazon S3. A service might do this using the calling principal's permissions, using a service role, or
using a service-linked role.
• Principal permissions – When you use an IAM user or role to perform actions in AWS, you are
considered a principal. Policies grant permissions to a principal. When you use some services, you
might perform an action that then triggers another action in a different service. In this case, you
must have permissions to perform both actions. To see whether an action requires additional
dependent actions in a policy, see Actions, Resources, and Condition Keys for Amazon CodeGuru
Reviewer in the Service Authorization Reference.
• Service role – A service role is an IAM role that a service assumes to perform actions on your behalf.
An IAM administrator can create, modify, and delete a service role from within IAM. For more
information, see Creating a role to delegate permissions to an AWS service in the IAM User Guide.
• Service-linked role – A service-linked role is a type of service role that is linked to an AWS service.
The service can assume the role to perform an action on your behalf. Service-linked roles appear
in your IAM account and are owned by the service. An IAM administrator can view, but not edit the
permissions for service-linked roles.
• Applications running on Amazon EC2 – You can use an IAM role to manage temporary credentials
for applications that are running on an EC2 instance and making AWS CLI or AWS API requests.
This is preferable to storing access keys within the EC2 instance. To assign an AWS role to an EC2
instance and make it available to all of its applications, you create an instance profile that is attached
to the instance. An instance profile contains the role and enables programs that are running on the
EC2 instance to get temporary credentials. For more information, see Using an IAM role to grant
permissions to applications running on Amazon EC2 instances in the IAM User Guide.
67
Amazon CodeGuru Reviewer User Guide
Managing access using policies
To learn whether to use IAM roles or IAM users, see When to create an IAM role (instead of a user) in the
IAM User Guide.
Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can
perform actions on what resources, and under what conditions.
Every IAM entity (user or role) starts with no permissions. In other words, by default, users can
do nothing, not even change their own password. To give a user permission to do something, an
administrator must attach a permissions policy to a user. Or the administrator can add the user to a
group that has the intended permissions. When an administrator gives permissions to a group, all users
in that group are granted those permissions.
IAM policies define permissions for an action regardless of the method that you use to perform the
operation. For example, suppose that you have a policy that allows the iam:GetRole action. A user with
that policy can get role information from the AWS Management Console, the AWS CLI, or the AWS API.
Identity-based policies
Identity-based policies are JSON permissions policy documents that you can attach to an identity, such
as an IAM user, group of users, or role. These policies control what actions users and roles can perform,
on which resources, and under what conditions. To learn how to create an identity-based policy, see
Creating IAM policies in the IAM User Guide.
Identity-based policies can be further categorized as inline policies or managed policies. Inline policies
are embedded directly into a single user, group, or role. Managed policies are standalone policies that
you can attach to multiple users, groups, and roles in your AWS account. Managed policies include AWS
managed policies and customer managed policies. To learn how to choose between a managed policy or
an inline policy, see Choosing between managed policies and inline policies in the IAM User Guide.
• Permissions boundaries – A permissions boundary is an advanced feature in which you set the
maximum permissions that an identity-based policy can grant to an IAM entity (IAM user or role).
You can set a permissions boundary for an entity. The resulting permissions are the intersection of
entity's identity-based policies and its permissions boundaries. Resource-based policies that specify
the user or role in the Principal field are not limited by the permissions boundary. An explicit deny
in any of these policies overrides the allow. For more information about permissions boundaries, see
Permissions boundaries for IAM entities in the IAM User Guide.
• Service control policies (SCPs) – SCPs are JSON policies that specify the maximum permissions for
an organization or organizational unit (OU) in AWS Organizations. AWS Organizations is a service for
grouping and centrally managing multiple AWS accounts that your business owns. If you enable all
features in an organization, then you can apply service control policies (SCPs) to any or all of your
accounts. The SCP limits permissions for entities in member accounts, including each AWS account
68
Amazon CodeGuru Reviewer User Guide
Overview of managing access
root user. For more information about Organizations and SCPs, see How SCPs work in the AWS
Organizations User Guide.
• Session policies – Session policies are advanced policies that you pass as a parameter when you
programmatically create a temporary session for a role or federated user. The resulting session's
permissions are the intersection of the user or role's identity-based policies and the session policies.
Permissions can also come from a resource-based policy. An explicit deny in any of these policies
overrides the allow. For more information, see Session policies in the IAM User Guide.
When you grant permissions, you decide who is getting the permissions, the resources they can access,
and the actions that can be performed on those resources.
Topics
• CodeGuru Reviewer resources and operations (p. 69)
• Understanding resource ownership (p. 70)
• Managing access to resources (p. 70)
• Specifying policy elements: actions, effects, and principals (p. 71)
For example, you can indicate a specific repository association with id my-repository-association-
id in your statement using its ARN, as follows.
69
Amazon CodeGuru Reviewer User Guide
Overview of managing access
"Resource": "arn:aws:codeguru-reviewer:us-east-2:123456789012:association:my-repository-
association-id"
To specify all resources, or if an API action does not support ARNs, use the wildcard character (*) in the
Resource element, as follows.
"Resource": "*"
To specify multiple resources in a single statement, separate their ARNs with commas, as follows.
"Resource": [
"arn:aws:codeguru-reviewer:us-east-2:123456789012:association:my-repository-
association-id-1",
"arn:aws:codeguru-reviewer:us-east-2:123456789012:association:my-repository-
association-id-2"
]
CodeGuru Reviewer provides a set of operations to work with the CodeGuru Reviewer resources. For a
list, see Amazon CodeGuru Reviewer permissions reference (p. 81).
• If you use the root account credentials of your AWS account to create a rule, your AWS account is the
owner of the CodeGuru Reviewer resource.
• If you create an IAM user in your AWS account and grant permissions to create CodeGuru Reviewer
resources to that user, the user can create CodeGuru Reviewer resources. However, your AWS account,
to which the user belongs, owns the CodeGuru Reviewer resources.
• If you create an IAM role in your AWS account with permissions to create CodeGuru Reviewer
resources, anyone who can assume the role can create CodeGuru Reviewer resources. Your AWS
account, to which the role belongs, owns the CodeGuru Reviewer resources.
Policies attached to an IAM identity are referred to as identity-based policies (IAM policies). Policies
attached to a resource are referred to as resource-based policies. CodeGuru Reviewer supports identity-
based (IAM policies) only.
Identity-based policies
You can attach policies to IAM identities. To grant a user permissions to view repository associations and
code reviews in the CodeGuru Reviewer console, you can attach a permissions policy to a user or group
that the user belongs to.
70
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
In CodeGuru Reviewer, identity-based policies are used to manage permissions to the resources related
to associated repositories and code reviews. For example, you can control access to code reviews.
You can create IAM policies to restrict the calls and resources that users in your account have access
to, and then attach those policies to IAM users. For more information about how to create IAM roles
and to explore example IAM policy statements for CodeGuru Reviewer, see Customer managed policy
examples (p. 77).
• Resource – You use an ARN to identify the resource that the policy applies to.
• Action – You use action keywords to identify resource operations to allow or deny. For example, the
codeguru-reviewer:DisassociateRepository permission gives the user permissions to perform
the DisassociateRepository operation.
• Effect – You specify the effect, either allow or deny, when the user requests the action. If you don't
explicitly grant access to (allow) a resource, access is implicitly denied. You can also explicitly deny
access to a resource. You might do this to make sure that a user cannot access a resource, even if a
different policy grants access.
• Principal – In identity-based policies (IAM policies), the user the policy is attached to is the implicit
principal. For resource-based policies, you specify the user, account, service, or other entity that you
want to receive permissions.
To learn more about IAM policy syntax and descriptions, see AWS IAM Policy Reference in the IAM User
Guide.
For a table showing all of the CodeGuru Reviewer API actions and the resources they apply to, see
Amazon CodeGuru Reviewer permissions reference (p. 81).
To learn how to create an IAM identity-based policy using these example JSON policy documents, see
Creating Policies on the JSON Tab in the IAM User Guide.
Topics
• Policy best practices (p. 72)
• Permissions required to use the CodeGuru Reviewer console (p. 72)
• AWS managed (predefined) policies for CodeGuru Reviewer (p. 73)
• CodeGuru Reviewer updates to AWS managed policies (p. 77)
• Customer managed policy examples (p. 77)
71
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
• Get started using AWS managed policies – To start using CodeGuru Reviewer quickly, use AWS
managed policies to give your employees the permissions they need. These policies are already
available in your account and are maintained and updated by AWS. For more information, see Get
started using permissions with AWS managed policies in the IAM User Guide.
• Grant least privilege – When you create custom policies, grant only the permissions required
to perform a task. Start with a minimum set of permissions and grant additional permissions as
necessary. Doing so is more secure than starting with permissions that are too lenient and then trying
to tighten them later. For more information, see Grant least privilege in the IAM User Guide.
• Enable MFA for sensitive operations – For extra security, require IAM users to use multi-factor
authentication (MFA) to access sensitive resources or API operations. For more information, see Using
multi-factor authentication (MFA) in AWS in the IAM User Guide.
• Use policy conditions for extra security – To the extent that it's practical, define the conditions under
which your identity-based policies allow access to a resource. For example, you can write conditions to
specify a range of allowable IP addresses that a request must come from. You can also write conditions
to allow requests only within a specified date or time range, or to require the use of SSL or MFA. For
more information, see IAM JSON policy elements: Condition in the IAM User Guide.
• CodeGuru Reviewer
• AWS CodeCommit (if your source code is in a CodeCommit repository)
• AWS CodeStar connections (if your source code is in a repository managed by AWS CodeStar
connections, such as Bitbucket)
• AWS Identity and Access Management (IAM)
If your source code is in a GitHub repository, you must have an OAuth token to connect to it. Associated
GitHub repositories are not managed by AWS CodeStar connections. For more information, see Git
automation with OAuth tokens on the GitHub website.
If you create an IAM policy that is more restrictive than the minimum required permissions, the console
won't function as intended.
The following shows an example of a permissions policy that allows a user to get information about a
repository association only in the us-east-2 Region for account 123456789012 for any repository
association with a universally unique identifier (UUID) that starts with 12345.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "codeguru-reviewer:DescribeRepositoryAssociation",
"Resource": "arn:aws:codeguru-reviewer:us-east-2:123456789012:association:12345*"
72
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
]
}
To create and manage CodeGuru Reviewer service roles, you must also attach the AWS managed policy
named IAMFullAccess.
You can also create your own custom IAM policies to allow permissions for CodeGuru Reviewer actions
and resources. You can attach these custom policies to the IAM users or groups that require those
permissions.
The following AWS managed policies, which you can attach to users in your account, are specific to
CodeGuru Reviewer.
Topics
• AmazonCodeGuruReviewerFullAccess (p. 73)
• AmazonCodeGuruReviewerReadOnlyAccess (p. 75)
• AmazonCodeGuruReviewerServiceRolePolicy (p. 75)
AmazonCodeGuruReviewerFullAccess
AmazonCodeGuruReviewerFullAccess – Provides full access to CodeGuru Reviewer, including
permissions to tag repository associations and to create, update, and delete code reviews and repository
associations. It also grants permission to related resources in other services that integrate with CodeGuru
Reviewer, such as Amazon CloudWatch, AWS CodeStar connections, and CodeCommit. Apply this only
to administrative-level users to who you want to grant full control over CodeGuru Reviewer repository
associations, code reviews, and related resources in your AWS account, including the ability to delete
code reviews and repository associations.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AmazonCodeGuruReviewerFullAccess",
"Effect": "Allow",
"Action": [
"codeguru-reviewer:*"
],
"Resource": "*"
},
{
"Sid": "AmazonCodeGuruReviewerSLRCreation",
"Action": "iam:CreateServiceLinkedRole",
"Effect": "Allow",
"Resource": "arn:aws:iam::*:role/aws-service-role/codeguru-
reviewer.amazonaws.com/AWSServiceRoleForAmazonCodeGuruReviewer",
"Condition": {
"StringLike": {
"iam:AWSServiceName": "codeguru-reviewer.amazonaws.com"
}
73
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
}
},
{
"Sid": "AmazonCodeGuruReviewerSLRDeletion",
"Effect": "Allow",
"Action": [
"iam:DeleteServiceLinkedRole",
"iam:GetServiceLinkedRoleDeletionStatus"
],
"Resource": "arn:aws:iam::*:role/aws-service-role/codeguru-
reviewer.amazonaws.com/AWSServiceRoleForAmazonCodeGuruReviewer"
},
{
"Sid": "codecommitAccess",
"Effect": "Allow",
"Action": [
"codecommit:ListRepositories"
],
"Resource": "*"
},
{
"Sid": "codecommitTagManagement",
"Effect": "Allow",
"Action": [
"codecommit:TagResource",
"codecommit:UntagResource"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": "codeguru-reviewer"
}
}
},
{
"Sid": "CodeConnectTagManagement",
"Effect": "Allow",
"Action": [
"codestar-connections:TagResource",
"codestar-connections:UntagResource",
"codestar-connections:ListTagsForResource"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": "codeguru-reviewer"
}
}
},
{
"Sid": "CodeConnectManagedRules",
"Effect": "Allow",
"Action": [
"codestar-connections:UseConnection",
"codestar-connections:ListConnections",
"codestar-connections:PassConnection"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"codestar-connections:ProviderAction": [
"ListRepositories",
"ListOwners"
]
}
}
74
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
},
{
"Sid": "CloudWatchEventsManagedRules",
"Effect": "Allow",
"Action": [
"events:PutRule",
"events:PutTargets",
"events:DeleteRule",
"events:RemoveTargets"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"events:ManagedBy": "codeguru-reviewer.amazonaws.com"
}
}
}
]
}
AmazonCodeGuruReviewerReadOnlyAccess
AmazonCodeGuruReviewerReadOnlyAccess – Grants read-only access to CodeGuru Reviewer and
related resources in other AWS services. Apply this policy to users who you want to grant the ability to
view code reviews, but not to create or make any changes to them.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AmazonCodeGuruReviewerReadOnlyAccess",
"Effect": "Allow",
"Action": [
"codeguru-reviewer:List*",
"codeguru-reviewer:Describe*",
"codeguru-reviewer:Get*"
],
"Resource": "*"
}
]
}
AmazonCodeGuruReviewerServiceRolePolicy
AmazonCodeGuruReviewerServiceRolePolicy – Grants permission to related resources in
CodeCommit, AWS CodeStar connections, Amazon S3, and CloudWatch that are required to create
repository associations.
For CodeCommit repository associations, the CodeCommit and CloudWatch permissions in this policy
are required. For associations with repositories that are managed by an AWS CodeStar connection, such
as Bitbucket, the AWS CodeStar connections permissions are required. For code reviews with security
analysis, the Amazon S3 permissions are required.
When you create your first association with a CodeCommit, Amazon S3, or AWS CodeStar connections
managed repository, CodeGuru Reviewer adds the AmazonCodeGuruReviewerServiceRolePolicy
policy to your AWS account. This policy grants CodeGuru Reviewer access to CodeCommit repositories,
AWS CodeStar connections resources in your account that have a aws:ResourceTag/codeguru-
reviewer tag. It also grants access to Amazon S3 buckets that have a prefix that begins with
codeguru-reviewer-. When you associate a CodeCommit repository, CodeGuru Reviewer adds this
75
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
tag to the repository. When you associate an AWS CodeStar connections managed repository, CodeGuru
Reviewer adds this tag to the AWS CodeStar connections resource, if it doesn't already exist.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AccessCodeGuruReviewerEnabledRepositories",
"Effect": "Allow",
"Action": [
"codecommit:GetRepository",
"codecommit:GetBranch",
"codecommit:DescribePullRequestEvents",
"codecommit:GetCommentsForPullRequest",
"codecommit:GetDifferences",
"codecommit:GetPullRequest",
"codecommit:ListPullRequests",
"codecommit:PostCommentForPullRequest",
"codecommit:GitPull",
"codecommit:UntagResource"
],
"Resource": "*",
"Condition": {
"StringLike": {
"aws:ResourceTag/codeguru-reviewer": "enabled"
}
}
},
{
"Sid": "AccessCodeGuruReviewerEnabledConnections",
"Effect": "Allow",
"Action": [
"codestar-connections:UseConnection"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"codestar-connections:ProviderAction": [
"ListBranches",
"GetBranch",
"ListRepositories",
"ListOwners",
"ListPullRequests",
"GetPullRequest",
"ListPullRequestComments",
"ListPullRequestCommits",
"ListCommitFiles",
"ListBranchCommits",
"CreatePullRequestDiffComment",
"GitPull"
]
},
"Null": {
"aws:ResourceTag/codeguru-reviewer": "false"
}
}
},
{
"Sid": "CloudWatchEventsResourceCleanup",
"Effect": "Allow",
"Action": [
"events:DeleteRule",
"events:RemoveTargets"
76
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
],
"Resource": "*",
"Condition": {
"StringEquals": {
"events:ManagedBy": "codeguru-reviewer.amazonaws.com"
}
}
},
{
"Sid": "AccessCodeGuruReviewerCreatedS3Bucket",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:CreateBucket",
"s3:ListBucket",
"s3:PutBucketPolicy",
"s3:PutLifecycleConfiguration"
],
"Resource": [
"arn:aws:s3:::codeguru-reviewer-*",
"arn:aws:s3:::codeguru-reviewer-*/*"
]
}
]
}
AmazonCodeGuruReviewerServiceRolePolicy
CodeGuru (p.
Reviewer
75) April 28, 2021
– Update to an existing policy added new permissions
to allow access to the
CreateBucket, ListBucket,
PutBucketPolicy, and
PutLifecycleConfiguration
actions on an Amazon S3 bucket
resource.
The following example IAM policies grant permissions for various CodeGuru Reviewer actions. Use them
to limit CodeGuru Reviewer access for your IAM users and roles. These policies control the ability to
perform actions with the CodeGuru Reviewer console, API, AWS SDKs, or the AWS CLI.
77
Amazon CodeGuru Reviewer User Guide
Using identity-based policies
Note
All examples use the US East (Ohio) Region (us-east-2) and contain fictitious account IDs.
Examples
• Example 1: Allow a user to see all recommendations created in an associated repository (p. 78)
• Example 2: Allow a user to view code reviews in an associated repository in a single Region (p. 78)
• Example 3: Allow a user to perform CodeGuru Reviewer operations in a single Region (p. 78)
• Example 4: Allow read-only access to CodeGuru Reviewer operations for a user connecting from a
specified IP address range (p. 79)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codeguru-reviewer:ListRecommendations"
],
"Resource": "arn:aws:codeguru-reviewer:us-
east-2:123456789012:association:association-uuid"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "codeguru-reviewer:DescribeCodeReview",
"Resource": "arn:aws:codeguru-reviewer:us-
east-2:123456789012:association:association-uuid"
}
]
}
78
Amazon CodeGuru Reviewer User Guide
Using tags to control access to associated repositories
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "codeguru-reviewer:*",
"Resource": "arn:aws:codeguru-reviewer:us-east-2:123456789012:*",
"Condition": {
"StringEquals": {
"aws:RequestedRegion": "us-east-2"
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codeguru-reviewer:List*",
"codeguru-reviewer:Describe*"
],
"Resource": "*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "203.0.113.0/24"
}
}
}
]
}
You can directly use tags on an associated repository to affect permissions on the following CodeGuru
Reviewer API operations:
• AssociateRepository
79
Amazon CodeGuru Reviewer User Guide
Using tags to control access to associated repositories
• DescribeRepositoryAssociation
• DisassociateRepositoryAssociation
You can use tags on an associated repository to indirectly affect permissions on a code review that
belongs to the associated repository. Use tags on an associated repository to affect permissions on the
following CodeGuru Reviewer API operations that are related to code reviews:
• CreateCodeReview
• ListRecommendations
• DescribeCodeReview
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"codeguru-reviewer:DescribeRepositoryAssociation"
],
"Resource": "*",
"Condition": {
"ForAnyValue:StringEquals": {
"aws:RequestTag/ViewAssocatedRepositoryDetails": "DenyViewRepository"
}
}
},
{
"Effect": "Deny",
"Action": [
"codeguru-reviewer:DisassociateRepository"
],
"Resource": "*",
"Condition": {
"ForAnyValue:StringEquals": {
"aws:TagKeys": ["DenyDisassociate"]
}
}
}
]
}
Example Example 2: Deny or allow actions on code reviews based on their associated
repository's resource tags
You can create a policy that allows or denies actions on CodeGuru Reviewer code reviews by using
the CodeGuru Reviewer tags that are added to their associated repositories. An associated repository
80
Amazon CodeGuru Reviewer User Guide
CodeGuru Reviewer permissions reference
contains code reviews, and you can use tags on the associated repository to affect permissions on its
code reviews. For example, you can create a policy that denies users the ability to view recommendations
created by code reviews in an associated repository. The following policy denies a user with AWS account
ID 123456789012 in the AWS Region us-west-2 from viewing recommendations created by code reviews
in all associated repositories that have a Recommendation tag with a value of Secret.
{
"Version": "2012-10-17",
"Statement" : [
{
"Effect" : "Deny",
"Action" : [
"codeguru-reviewer:ListRecommendations"
]
"Resource" : "arn:aws:codeguru-reviewer:us-west-2123456789012:association:*",
"Condition" : {
"StringEquals" : "aws:ResourceTag/Recommendations": "Secret"
}
}
]
}
Example Example 3: Limit all possible CodeGuru Reviewer actions to associated repositories
based on resource tags
You can create policies that selectively allow CodeGuru Reviewer actions on all associated repositories
that are not tagged with specific tags. For example, the following policy allows you to associate,
disassociate, and view the details of associated repositories that are not tagged with the specified tags:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codeguru-reviewer:AssociateRepository",
"codeguru-reviewer:DescribeRepositoryAssociation",
"codeguru-reviewer:DisassociateRepositoryAssociation"
],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:ResourceTag/Status": "AssociatedRepositoryAllow",
"aws:ResourceTag/Team": "Saanvi"
}
}
}
]
}
You specify the actions in the policy's Action field. To specify an action, use the codeguru-
reviewer: prefix followed by the API operation name (for example, codeguru-
reviewer:AssociateRepository and codeguru-reviewer:DisassociateRepository).
To specify multiple actions in a single statement, separate them with commas (for example,
81
Amazon CodeGuru Reviewer User Guide
CodeGuru Reviewer permissions reference
You specify an Amazon Resource Name (ARN), with or without a wildcard character (*), as the resource
value in the policy's Resource field. You can use a wildcard to specify multiple actions or resources.
For example, codeguru-reviewer:* specifies all CodeGuru Reviewer actions and codeguru-
reviewer:List* specifies all CodeGuru Reviewer actions that begin with the word List. The following
example refers to all repository associations with a universally unique identifier (UUID) that begins with
PullRequest-GITHUB.
arn:aws:codeguru-reviewer:us-east-2:123456789012:association:PullRequest-GITHUB*
You can use the following table as a reference when you are setting up Authenticating with identities
in CodeGuru Reviewer (p. 66) and writing permissions policies that you can attach to an IAM identity
(identity-based policies).
AssociateRepository
Action: codeguru-reviewer:AssociateRepository
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
DescribeCodeReview
Action: codeguru-reviewer:DescribeCodeReview
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
DescribeRecommendationFeedback
Action: codeguru-reviewer:DescribeRecommendationFeedback
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
DescribeRepositoryAssociation
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid
DisassociateRepository
Action: codeguru-reviewer:DisassociateRepository
82
Amazon CodeGuru Reviewer User Guide
Troubleshooting
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid
ListCodeReviews
Action: codeguru-reviewer:ListCodeReviews
Required to view the names of all code reviews in the current AWS account that were created in the
past 90 days.
Resource: *
ListRecommendationFeedback
Action: codeguru-reviewer:ListRecommendationFeedback
Required to list all users' customer feedback for a code review recommendation.
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
ListRecommendations
Action: codeguru-reviewer:ListRecommendations
Required to view a list of all the recommendations for one completed code review.
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
ListRepositoryAssociations
Action: codeguru-reviewer:ListRepositoryAssociations
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid
PutRecommendationFeedback
Action: codeguru-reviewer:PutRecommendationFeedback
Resource: arn:aws:codeguru-reviewer:region-ID:account-
ID:association:repository-association-uuid:code-review:code-review-uuid
Topics
• I am not authorized to perform an action in CodeGuru Reviewer (p. 84)
• I am not authorized to perform iam:PassRole (p. 84)
• I want to view my access keys (p. 84)
83
Amazon CodeGuru Reviewer User Guide
Troubleshooting
• I'm an administrator and want to allow others to access CodeGuru Reviewer (p. 85)
The following example error occurs when the mateojackson IAM user tries to use the console to
view details about a code review, but does not have codeguru-reviewer:DescribeCodeReview
permissions.
In this case, Mateo asks his administrator to update his policies to allow him to access the my-example-
code-review resource using the codeguru-reviewer:DescribeCodeReview action.
Some AWS services allow you to pass an existing role to that service, instead of creating a new service
role or service-linked role. To do this, you must have permissions to pass the role to the service.
The following example error occurs when an IAM user named marymajor tries to use the console to
perform an action in CodeGuru Reviewer. However, the action requires the service to have permissions
granted by a service role. Mary does not have permissions to pass the role to the service.
In this case, Mary asks her administrator to update her policies to allow her to perform the
iam:PassRole action.
Access keys consist of two parts: an access key ID (for example, AKIAIOSFODNN7EXAMPLE) and a secret
access key (for example, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY). Like a user name and
password, you must use both the access key ID and secret access key together to authenticate your
requests. Manage your access keys as securely as you do your user name and password.
Important
Do not provide your access keys to a third party, even to help find your canonical user ID. By
doing this, you might give someone permanent access to your account.
When you create an access key pair, you are prompted to save the access key ID and secret access key in
a secure location. The secret access key is available only at the time you create it. If you lose your secret
access key, you must add new access keys to your IAM user. You can have a maximum of two access keys.
If you already have two, you must delete one key pair before creating a new one. To view instructions,
see Managing access keys in the IAM User Guide.
84
Amazon CodeGuru Reviewer User Guide
Logging and monitoring
To get started right away, see Creating your first IAM delegated user and group in the IAM User Guide.
Topics
• Logging CodeGuru Reviewer API calls with AWS CloudTrail (p. 85)
• Monitoring CodeGuru Reviewer with Amazon CloudWatch (p. 87)
If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket,
including events for CodeGuru Reviewer. 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 CodeGuru Reviewer, 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, including how to configure and enable it, see the AWS CloudTrail User
Guide.
For an ongoing record of events in your AWS account, including events for CodeGuru Reviewer, create a
trail. A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. By default, when you create
a trail in the console, the trail applies to all AWS Regions. The trail logs events from all Regions in the
AWS partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can
configure other AWS services to further analyze and act on the event data collected in CloudTrail logs.
For more information, see the following:
85
Amazon CodeGuru Reviewer User Guide
Logging CodeGuru Reviewer API calls with AWS CloudTrail
CodeGuru Reviewer supports logging the following actions as events in CloudTrail log files:
• AssociateRepository
• DescribeCodeReview
• DescribeRecommendationFeedback
• DescribeRepositoryAssociation
• DisassociateRepository
• ListCodeReviews
• ListRecommendationFeedback
• ListRecommendations
• ListRepositoryAssociations
• PutRecommendationFeedback
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 AWS Identity and Access Management (IAM) 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
The following example shows a CloudTrail log entry that demonstrates the AssociateRepository
action.
{
"eventVersion": "1.05",
"userIdentity": {
"type": "AssumedRole",
"principalId": "AAAAAAAAAEXAMPLE:TestSession",
"arn": "arn:aws:sts::123456789012:assumed-role/TestRole/TestSession",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"sessionContext": {
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2019-11-27T02:06:30Z"
86
Amazon CodeGuru Reviewer User Guide
Monitoring CodeGuru Reviewer with CloudWatch
},
"sessionIssuer": {
"type": "Role",
"principalId": "AIDACKCEVSQ6C2EXAMPLE",
"arn": "arn:aws:iam::123456789012:role/TestRole",
"accountId": "123456789012",
"userName": "TestRole"
}
}
},
"eventTime": "2019-11-27T03:46:35Z",
"eventSource": "codeguru-reviewer.amazonaws.com",
"eventName": "AssociateRepository",
"awsRegion": "us-west-2",
"sourceIPAddress": "52.13.164.128",
"userAgent": "aws-internal/3 aws-sdk-java/1.11.672 Linux/4.14.138-99.102.amzn2.x86_64
OpenJDK_64-Bit_Server_VM/25.201-b09 java/1.8.0_201 vendor/Oracle_Corporation exec-env/
AWS_Lambda_java8",
"requestParameters": {
"ClientRequestToken": "7485aa2f-ce15-4bc6-a6cc-2a76d702f15f",
"Repository": {
"CodeCommit": {
"Name": "repository-name"
}
}
},
"responseElements": {
"RepositoryAssociation": {
"AssociationArn": "arn:aws:codeguru-reviewer:us-
west-2:123456789012:association:6eda8e7a-319a-4750-bca8-7f73a816fadc",
"AssociationId": "6eda8e7a-319a-4750-bca8-7f73a816fadc",
"CreatedTimeStamp": 1574826395.662,
"LastUpdatedTimeStamp": 1574826395.662,
"Name": "TestRepository",
"Owner": "123456789012",
"ProviderType": "CodeCommit",
"State": "Associating",
"StateReason": "Pending Repository Association"
}
},
"requestID": "cb8c167e-EXAMPLE",
"eventID": "e3c6f4ce-EXAMPLE",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
}
• ProviderType — View the number of recommendations for a provider type. You can view the count
of recommendations in all repositories in AWS CodeCommit, your Bitbucket account, your GitHub
account, or your GitHub Enterprise Server account, over a period of time.
• CodeReviewType — View the number of recommendations for a code review type. The one available
code review type is PullRequest. Use it to view the count of recommendations in one pull request.
• RepositoryName — View the count of recommendations for one repository over a period of time.
87
Amazon CodeGuru Reviewer User Guide
Monitoring CodeGuru Reviewer with CloudWatch
You can set a CloudWatch alarm that notifies you when the number of recommendations exceeds a
threshold you set.
For more information about creating and using CloudWatch alarms and metrics, see Using Amazon
CloudWatch metrics.
You can track the following metric for each dimension over a period of time.
Metric Description
Units: Count
Topics
• Monitoring profiling groups with CloudWatch metrics (p. 88)
• Monitoring CodeGuru Reviewer recommendations with CloudWatch alarms (p. 88)
1. Sign in to the AWS Management Console and open the CloudWatch console at https://
console.aws.amazon.com/cloudwatch/.
2. In the navigation pane, choose Metrics.
3. On the All metrics tab, choose AWS/CodeGuruReviewer.
4. Choose the dimension you want metrics for: ProviderType, CodeReviewType, or RepositoryName.
The graph on the page displays metrics for recommendations for all selected items that are available
for the selected dimension.
An alarm watches the number of recommendations for one of three CodeGuru Reviewer CloudWatch
dimensions that you specify:
• ProviderType — View the number of recommendations for a provider type. You can view the count
of recommendations in all repositories in AWS CodeCommit, your Bitbucket account, your GitHub
account, or your GitHub Enterprise Server account, over a period of time.
• CodeReviewType — View the number of recommendations for a code review type. The one available
code review type is PullRequest. Use it to view the count of recommendations in one pull request.
• RepositoryName — View the count of recommendations for one repository over a period of time.
88
Amazon CodeGuru Reviewer User Guide
Compliance validation
You set one or more actions that happen when the number of recommendations for a dimension exceeds
a count over a number of time periods you choose. For example, you can specify that an Amazon SNS
notification is sent when more than 25 recommendations are generated for a branch in a repository
within an hour.
A user or role must have CloudWatch PutMetricAlarm permissions to create an alarm. For more
information, see Using identity-based policies for CodeGuru Reviewer (p. 71) and Amazon
CloudWatch permissions reference in the Amazon CloudWatch User Guide.
1. Sign in to the AWS Management Console and open the CloudWatch console at https://
console.aws.amazon.com/cloudwatch/.
2. In the navigation pane, choose Alarms.
3. Choose Create alarm.
4. Choose Select metric.
5. Choose AWS/CodeGuruReviewer.
6. Choose the dimension to monitor: ProviderType, CodeReviewType, or RepositoryName. Then
choose a metric to create an alarm for.
7. Continue through the process to create your alarm.
For more information about setting up CloudWatch alarms in the CloudWatch console, see Using
Amazon CloudWatch alarms in the Amazon CloudWatch User Guide.
To learn whether CodeGuru Reviewer or other AWS services are in scope of specific compliance
programs, see AWS Services in Scope by Compliance Program. For general information, see AWS
Compliance Programs.
You can download third-party audit reports using AWS Artifact. For more information, see Downloading
Reports in AWS Artifact.
Your compliance responsibility when using AWS services is determined by the sensitivity of your data,
your company's compliance objectives, and applicable laws and regulations. AWS provides the following
resources to help with compliance:
• Security and Compliance Quick Start Guides – These deployment guides discuss architectural
considerations and provide steps for deploying baseline environments on AWS that are security and
compliance focused.
• Architecting for HIPAA Security and Compliance Whitepaper – This whitepaper describes how
companies can use AWS to create HIPAA-eligible applications.
Note
Not all AWS services are HIPAA eligible. For more information, see the HIPAA Eligible Services
Reference.
• AWS Compliance Resources – This collection of workbooks and guides might apply to your industry
and location.
• Evaluating Resources with Rules in the AWS Config Developer Guide – The AWS Config service assesses
how well your resource configurations comply with internal practices, industry guidelines, and
regulations.
89
Amazon CodeGuru Reviewer User Guide
VPC endpoints (AWS PrivateLink)
• AWS Security Hub – This AWS service provides a comprehensive view of your security state within AWS
that helps you check your compliance with security industry standards and best practices.
• AWS Audit Manager – This AWS service helps you continuously audit your AWS usage to simplify how
you manage risk and compliance with regulations and industry standards.
You establish a private connection between your VPC and CodeGuru Reviewer by creating an interface
VPC endpoint. Interface endpoints are powered by AWS PrivateLink, a technology that enables you to
privately access CodeGuru Reviewer APIs without an internet gateway, NAT device, VPN connection, or
AWS Direct Connect connection. Instances in your VPC don't need public IP addresses to communicate
with CodeGuru Reviewer APIs. Traffic between your VPC and CodeGuru Reviewer does not leave the
Amazon network.
Each interface endpoint is represented by one or more Elastic Network Interfaces in your subnets.
For more information, see Interface VPC endpoints (AWS PrivateLink) in the Amazon VPC User Guide.
Note
CodeGuru Reviewer does not support Amazon VPC endpoint policies.
CodeGuru Reviewer supports making calls to all of its API actions from your VPC.
VPC endpoint policies are not supported for CodeGuru Reviewer. By default, full access to CodeGuru
Reviewer is allowed through the endpoint. For more information, see Controlling access to services with
VPC endpoints in the Amazon VPC User Guide.
Create a VPC endpoint for CodeGuru Reviewer using the following service name:
• com.amazonaws.region.codeguru-reviewer
If you enable private DNS for the endpoint, you can make API requests to CodeGuru Reviewer using its
default DNS name for the Region, for example, codeguru-reviewer.us-east-1.amazonaws.com.
90
Amazon CodeGuru Reviewer User Guide
Infrastructure security
For more information, see Accessing a service through an interface endpoint in the Amazon VPC User
Guide.
You use AWS published API calls to access CodeGuru Reviewer through the network. Clients must
support Transport Layer Security (TLS) 1.0 or later. We recommend TLS 1.2 or later. Clients must also
support cipher suites with perfect forward secrecy (PFS) such as Ephemeral Diffie-Hellman (DHE) or
Elliptic Curve Ephemeral Diffie-Hellman (ECDHE). Most modern systems such as Java 7 and later support
these modes.
Requests must be signed by using an access key ID and a secret access key that is associated with an
IAM principal. Or you can use the AWS Security Token Service (AWS STS) to generate temporary security
credentials to sign requests.
91
Amazon CodeGuru Reviewer User Guide
CodeCommit repositories
CodeCommit repositories
Resource Default
Tags
Tag limits apply to tags on CodeGuru Reviewer associated repository resources.
Resource Default
Maximum number of tags you can associate with a 50 (tags are case sensitive).
resource
92
Amazon CodeGuru Reviewer User Guide
CodeGuru Reviewer quotas for creating,
deploying, and managing an API
The default quota for all except three CodeGuru Reviewer APIs is 1 request per second per account.
None of these quotas can be increased. For a list of all CodeGuru Reviewer APIs, see Amazon CodeGuru
Reviewer Actions.
The three APIs with different default quotas are in the following table.
93
Amazon CodeGuru Reviewer User Guide
Where can I check the status of a repository association?
Troubleshooting
This section helps you troubleshoot common problems you might encounter when working with Amazon
CodeGuru Reviewer.
Topics
• Where can I check the status of a repository association? (p. 94)
• Where can I check the status of a code review? (p. 94)
• Where can I check the status of a third-party source provider connection? (p. 95)
• My repository is in an associated state. Why don't I see recommendations? (p. 95)
• Why did my association fail? (p. 95)
• Why did my code review fail? (p. 95)
• What if I disagree with the recommendation? (p. 96)
• How do I suppress a recommendation? (p. 96)
• The repository status has been associating for more than 5 minutes. What should I do? (p. 96)
• The code review status has been Pending for more than 15 minutes. What should I do? (p. 96)
• How do you access a repository if its owner is no longer available? (p. 97)
• Can I use the same AWS CodeStar connection to access repositories in two different
accounts? (p. 97)
• I'm trying to connect to my third-party repositories. What is the difference between an app
installation and a connection? Which one can be used to adjust permissions? (p. 97)
• How do I know if CodeGuru Reviewer used my aws-codeguru-reviewer.yml file in a code
review? (p. 97)
• Why didn't my costs decrease when I used an aws-codeguru-reviewer.yml file? (p. 99)
You can also use the AWS CLI or the AWS SDK. First call ListRepositoryAssociations to find the
association ID, then call DescribeAssociation.
You can also use the AWS CLI or the AWS SDK. If you have the code review Amazon Resource Name
(ARN), you can call DescribeCodeReview. Alternatively, you can call ListCodeReviews and filter
using ProviderType and RepositoryName.
94
Amazon CodeGuru Reviewer User Guide
Where can I check the status of a third-
party source provider connection?
If you can see your connection displayed there with a status of Available, you should be able to return to
the CodeGuru console and find your connection. Try refreshing the display in the console if you haven't
already. Your connection only displays on the CodeGuru console if it has a status of Available. The
console does not display connections with a status of Pending or Error.
You can check the status of a repository association in the CodeGuru console.
1. In the navigation pane, choose Reviewer, and then choose Repositories to navigate to the
Repositories page. This page lists all the associated repositories and their statuses.
2. Select the association for which you want to see status details.
3. From the Action list, choose View repository details. A small window opens with information about
the repository and the association status.
You can also use the AWS CLI or the AWS SDK. First, call ListRepositoryAssociations to find the
association ID, then call DescribeAssociation.
When you have fixed the problem, retry associating the repository.
95
Amazon CodeGuru Reviewer User Guide
What if I disagree with the recommendation?
• Source code access permissions are revoked, and CodeGuru Reviewer was not able to clone the source
code to review. In CodeCommit, this usually happens when the customer removes the codeguru-
reviewer–enabled repository tag from the repository. The easiest way to fix this is to disassociate
the repository and then associate the repository again.
• The pull request being reviewed has been closed, or the branch being reviewed has been deleted, and
CodeGuru Reviewer was not able to clone the source code to review before that occurred. Wait for
CodeGuru Reviewer to finish reviewing your code before deleting the source branch or closing the pull
request.
In CodeCommit, a thumbs-up or thumbs-down icon is provided next to the comments that you can use
to respond to comments made by CodeGuru Reviewer. In other repository source providers, you can reply
to a comment made by CodeGuru Reviewer, and include a thumbs-up or thumbs-down emoji in your
comment to indicate whether it was helpful. You can also go to the Code reviews page on the CodeGuru
Reviewer console and select the name of a code review to view details and recommendations from that
code review. There are thumbs-up and thumbs-down icons there under each recommendation that you
can choose to indicate whether the recommendation was helpful.
96
Amazon CodeGuru Reviewer User Guide
How do you access a repository if
its owner is no longer available?
about a code review status on the console, navigate to the Code reviews page and choose the name of
the code review that failed.
1. In the CodeGuru Reviewer console, choose Code reviews. This page lists all code reviews performed.
2. Choose a code review in the list.
• If CodeGuru Reviewer used your file in the code review, then Success appears under Analysis
configuration file.
97
Amazon CodeGuru Reviewer User Guide
How do I know if CodeGuru Reviewer used my
aws-codeguru-reviewer.yml file in a code review?
• If CodeGuru Reviewer found errors in your file, then Error appears under Analysis configuration
file and a message indicating the errors appears at the top of the page.
Also, Failed appears under Status, indicating that CodeGuru Reviewer did not perform a code
review.
Fix your aws-codeguru-reviewer.yml file based on the error messages and then initiate a
new full repository analysis. For more information, see Error handling for the aws-codeguru-
reviewer.yml file (p. 47).
• If CodeGuru Reviewer did not recognize your file name or find the file at the root directory
of your repository, then No file detected appears under Analysis configuration file. Your file
must be named aws-codeguru-reviewer.yml and must exist in the root directory of your
repository. Otherwise CodeGuru Reviewer cannot recognize that the file exists, use it in code
reviews, or return error messages about problems with the file.
Confirm the name and location of your file, make any needed changes, and then initiate a new
code review.
98
Amazon CodeGuru Reviewer User Guide
Why didn't my costs decrease when I
used an aws-codeguru-reviewer.yml file?
99
Amazon CodeGuru Reviewer User Guide
Updated topic (p. 100) CodeGuru Reviewer now retains March 2, 2022
forever the OAuth token created
after you connect to your GitHub
account. For more information,
see Captured data and Data
retention.
Updated topic (p. 100) CodeGuru Reviewer now January 26, 2022
references the new Amazon
CodeGuru Reviewer Detector
Library. The Detector Library
lists the detectors that
CodeGuru Reviewer uses to
analyze your code and provides
detailed information about these
detectors. For more information,
see Recommendation types and
the Amazon CodeGuru Reviewer
Detector Library.
New topic (p. 100) CodeGuru Reviewer now November 28, 2021
supports the detection of
unprotected secrets in your
code. For more information, see
Secrets detection.
New topic (p. 100) CodeGuru Reviewer now June 24, 2021
supports code reviews with
GitHub Actions. For more
information, see Create code
reviews with GitHub Actions.
New topic (p. 100) CodeGuru Reviewer now April 26, 2021
supports encryption of an
100
Amazon CodeGuru Reviewer User Guide
Updated topic (p. 100) CodeGuru Reviewer now November 25, 2020
supports analysis that helps
you improve the quality of your
code.
New topic (p. 100) CodeGuru Reviewer now November 19, 2020
supports adding tags to
associated repositories. For
more information, see Tagging a
repository association.
New topic (p. 100) CodeGuru Reviewer now September 11, 2020
supports AWS PrivateLink.
Use VPC endpoints when
calling CodeGuru Reviewer
API operations to increase the
security. For more information,
see CodeGuru Reviewer and
interface Amazon VPC endpoints
(AWS PrivateLink).
New topic (p. 100) This user guide now includes August 3, 2020
information about repository
analysis scans. You can now
enable CodeGuru Reviewer to
provide recommendations on all
the code in a branch at any time
with repository analysis code
reviews. For more information,
see About repository analysis
and pull request scans.
101
Amazon CodeGuru Reviewer User Guide
New topic (p. 100) This user guide now includes a June 19, 2020
tutorial that shows you how to
create a repository association
with a GitHub repository that
has example code. The example
code is intentionally suboptimal,
so CodeGuru Reviewer generates
a recommendation on a pull
request you create. For more
information, see Tutorial:
monitor source code in GitHub.
New topic (p. 100) This user guide now includes a June 11, 2020
security section. Learn about
data retention, IAM policies,
monitoring your profiling groups
with AWS CloudTrail, and more.
For more information, see
Security in CodeGuru Reviewer.
Preview release (p. 100) This is the preview release of the December 3, 2019
Amazon CodeGuru Reviewer User
Guide.
102
Amazon CodeGuru Reviewer User Guide
AWS glossary
For the latest AWS terminology, see the AWS glossary in the AWS General Reference.
103