Code quality is a growing concern for enterprises building cloud-native applications. Amazon CodeGuru is a developer tool from AWS that lets developers identify their application's most expensive lines. The tool then provides recommendations for remediation.
CodeGuru also monitors application performance in production. It then delivers recommendations to developers about how they can further improve code quality and application performance while helping reduce your cloud costs.
Inside Amazon CodeGuru
With the AWS Free Tier, CodeGuru is available at no cost for 90 days. You can review up to 100,000 lines of code for CodeGuru Reviewer. CodeGuru has two services:
- CodeGuru Profiler. CodeGuru Profiler lets your DevOps team visualize application performance from a centralized dashboard. Here, they can troubleshoot application latency and CPU utilization problems. It also allows your team to learn where they can reduce the infrastructure costs for an application.
- CodeGuru Reviewer. CodeGuru Reviewer lets your DevOps team detect defects in software code using machine learning. It offers suggestions for improving your Java and Python code as part of its analysis and guidelines on addressing the defects. CodeGuru Reviewer works with the following Java and Python code repositories: AWS CodeCommit, Amazon S3, Bitbucket, GitHub, GitHub Enterprise Cloud and GitHub Enterprise Server.
How to use Amazon CodeGuru
For this tutorial, access CodeGuru through the AWS Console. Set up and configure your CodeGuru environment. AWS includes complete documentation to guide you through the following setup steps:
- Sign up for AWS.
- Configure IAM permissions for CodeGuru Reviewer.
- Install or upgrade and then configure the AWS CLI.
- Create a repository for your source code.
Open Amazon CodeGuru
Access Amazon Code Guru from the AWS Console:
Step 1. Log in to the AWS Console using your authorized credentials.
Step 2. Type Amazon CodeGuru into the search field.
Access CodeGuru recommendations
From the code reviews page, select the code analysis you want to view. My example code received 125 recommendations.
When you click on the hyperlinked title of the recommendation, CodeGuru takes you to the line of code in GitHub that the recommendation mentions.
How to use CodeGuru Profiler
To start using CodeGuru Profiler:
Step 1. Choose CodeGuru Profiler in the Getting Started drop-down list.
Step 2. Click Get Started.
Step 3. Type in a descriptive name for your profiling group in the name field.
Step 4. Choose your compute platform.
Step 5. Optionally, click Add new tag to tag your resources.
Step 6. Advance to the setup page, it appears similar to the following:
Step 7. Follow the steps and prompts to set the permissions and start the monitoring agent.
View profiling groups
Go to the left-hand menu and click on Profiling groups. The profiling groups accessible to you are visible. Select a profiling group to view.
You also have access to recommendations similar to the following:
How to use CodeGuru Reviewer
CodeGuru Reviewer lets you create CI workflows, run a code analysis and review recommendations from the code analysis.
Create CI workflows in GitHub
Deploying CodeGuru Reviewer as part of a DevOps continuous integration/continuous development (CI/CD) toolchain is a step toward automation of code reviews during development. AWS doesn't restrict you to just AWS tools for integrations.
Create a CI workflow in GitHub
Step 1. Select CI workflows from the left-hand menu.
Step 2. Optionally, click Set up CI workflow with GitHub. The Amazon CodeGuru for GitHub Actions appears. Copy and paste the code snippet into your GitHub Actions .yml file.
Run a code analysis and review
Amazon CodeGuru Reviewer lets you run two types of code analysis:
- Incremental code reviews that automatically run when you make a pull request, which CodeGuru stores for 90 days.
- Full repository analysis on a code branch from an associated repository.
Perform a code review
Step 1. Open Amazon CodeGuru from the AWS Console.
Step 2. Select Associate repository.
Step 3. Choose your source provider. For this tutorial, I chose a GitHub repository.
Step 4. Follow the prompts to connect CodeGuru to your GitHub account.
Step 5. Build your repository analysis by selecting a source branch. Then you have the option to name your code review. I called my analysis CodeGuru-Review.
Step 6. Click Associate repository and Run analysis. The code reviews page will appear in 5 to 10 minutes.
Optional steps include the following:
- Enter encryption keys.
- Suppress recommendations from CodeGuru Reviewer using an analysis configuration file.
- Tag your repository analysis.