Delve into the depths of Amazon CodeWhisperer
Tags: aws, codewhisperer, programming, developers
Published: 2024-03-01 16:51:25


In continuation to the blog [AI-led development - Balancing risk with innovation](https://dev.to/aws-heroes/ai-led-development-balancing-risk-with-innovation-4335), here you go with the deep dive of AI-powered code companion, Amazon CodeWhisperer. It offers an in-depth exploration of CodeWhisperer's features and capabilities, aiming to provide developers with a thorough understanding of how it can elevate their coding experience and productivity.

### Table of Contents
* [Customer Challenges](#challenges)
* [Amazon CodeWhisperer](#code)
* [Key Pointers](#key)
* [Privacy with CodeWhisperer Generated Content](#privacy)
* [Security scan overview](#security)
* [Measure ongoing impact](#impact)
* [AWS Toolkit Installation & Configuration](#toolkit)
* [Amazon CodeWhisperer usage instructions](#usage)
* [Getting started with python coding](#python)
* [AWS re:Invent 2024](#reinvent)
* [Pricing](#pricing)
* [Resources](reflinks)
* [Conclusion](#conclusion)

### Customer Challenges <a name="challenges"></a>
Building reliable and secure code quickly presents challenges due to various factors, including: 
* Limited availability of developers
* Ensuring data privacy
* Time spent on repetitive, non-unique code
* Proper utilisation of open-source software
* Time invested in learning new technologies, APIs, and best practices
* Writing code that is secure
* Writing Test case improvement

### Amazon CodeWhisperer <a name="code"></a>
Go build applications faster and more securely with your AI coding companions
* Generate code suggestions in real time
* Scan code for hard-to-find vulnerabilities
* Flag code that resembles open-source training data or filter by default

> Amazon ran a productivity challenge, and participants who used CodeWhisperer were 27% more likely to complete the tasks successfully and did so an average of 57% faster than those who did not use CodeWhisperer.

**Note**: CodeWhisperer comes built in with AWS Cloud9,  the AWS Lambda console, [Amazon SageMaker Studio](https://docs.aws.amazon.com/codewhisperer/latest/userguide/sagemaker-setup.html), Amazon Glue Studio and is also available as extensions to popular IDEs including Visual Studio Code, IntelliJ, PyCharm etc.
Use code generation with the following tools to build applications faster and more securely with your AI coding companion

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nj6244qi78b7jgaurl2j.png)

### Key Pointers <a name="key"></a>
Here are key points about Amazon CodeWhisperer:
* _Real-time Code Suggestions:_ Provides developers with context-aware code suggestions and best practices in real-time.
* _Developer Ownership:_ Developers own the code they write, including suggestions provided by CodeWhisperer.
* _Enhanced Security:_ CodeWhisperer provides code suggestions based on the pre-trained data which are analyzed for security vulnerabilities but that does mean that it is totally free from vulnerabilities. It is recommended to scan Python, Java, and JavaScript projects with CodeWhisperer's built-in code scanning feature.
* _Integration with Major IDEs:_ Works seamlessly with popular IDEs like JetBrains, Visual Studio Code, and AWS Cloud9.
* _Improves Developer Productivity:_ Helps developers write code faster and more efficiently, reducing time spent on troubleshooting.
* _Support for Multiple Languages:_ Supports languages like Python, Java, and JavaScript, making it versatile for various development projects.
* _Native Integration with AWS Lambda Console:_ Available as a native code suggestion feature in the AWS Lambda console.
* _Results from Productivity Challenge:_ Participants using CodeWhisperer were 27% more likely to complete tasks successfully and did so 57% faster than those who did not use it.
* _Focus on Quality and Security:_ By addressing code quality and security issues early, developers can improve overall application quality and security while increasing development speed.

### Privacy with CodeWhisperer Generated Content <a name="privacy"></a>
* CodeWhisperer Individual uses your content, such as code snippets, comments, cursor location, and contents from files open in the IDE as inputs to provide code suggestions. You can opt out of allowing AWS to store and use your content for service improvement by adjusting the "Share CodeWhisperer Content with AWS" setting in the AWS Toolkit in the IDE
* Individual tier users can opt out to include suggestions with code references with checkbox from IDE (Visual Studio, Visual Studio Code, and JetBrains)
* Content processed by Amazon CodeWhisperer Professional, such as code snippets, comments, and contents from files open in the IDE, is not stored or used to train the model
* Professional Tier users can control this setting via IAM Identity Center. For multi-accounts, once enabled / disabled centrally, cannot be changed by the individual developers.
* CodeWhisperer captures telemetry data to understand the number of active users, number of recommendations accepted / rejected, number of authorised users etc.

### Security scan overview <a name="security"></a>
* Security scans in CodeWhisperer identify security vulnerabilities and suggest how to improve your code.
* CodeWhisperer security scan feature works with the following programming languages 
  * Java, Javascript, Python, C#, TypeScript, Ruby and Go
  * Infrastructure as Code (IaC) - AWS CloudFormation, Terraform, AWS CDK for TypeScript and Python
* CodeWhisperer will only provide code remediation suggestions for code written in Java 	Python, or JavaScript.

### Measure ongoing impact <a name="impact"></a>
Continuous monitoring is crucial for evaluating the impact and value add of adopting a new tool. Establish a baseline with whatever tools that you have in place today. Then enable a change / new service / tool and review the resulting data. 
Amazon CodeWhisperer provides usage and activity metrics through the Dashboard in the console that can form part of the story. Changes across the organisation will take time to flow in but however you will start seeing the indications of change in a 30 or 60 day period while you explore the tool. That's a good sign. 
Customers obviously are looking for efficiency gains to offset the cost of the tools and the efficiency is a little subjective which depends on the internal culture too. However, customers who have implemented DevOps can consider using DORA ([https://dorametrics.org](https://dorametrics.org)) for their reference. DORA metrics, which stand for Deliverability, Operations and Research Administration, are a set of standards used to measure the performance and efficiency of various engineering systems and processes.
Security scans are often seen as someone else's responsibility, introduced late in the development cycle. It's advisable for developers to conduct security scans of their code within the IDE and address any identified quality and security issues. This proactive approach not only enhances the overall quality and security of the code but also improves the speed of development.

### AWS Toolkit Installation & Configuration <a name="toolkit"></a>
You should be able to use Amazon CodeWhisperer within your favourite IDE – be it Visual Studio Code or JetBrain following the guide for [Installing the AWS Toolkit for Visual Studio Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-toolkit.html) or  [Installing the AWS Toolkit for JetBrains](https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/setup-toolkit.html). 
**Setup Amazon Q in Visual Studio Code**
* For this blog, let's proceed with Visual Studio Code and you may follow the above instructions to install AWS Toolkit for Visual Studio Code followed by VS Code Extension from [AWS Marketplace](https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.aws-toolkit-vscode)
* Create BuilderID using [instructions](https://us-east-1.signin.aws/platform/login?workflowStateHandle=b62dd9f0-eab4-4032-94e8-ff10ba215ed4) provided
Here you go with the flow of steps
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/krgwo04wzhiqnkf8k98x.png)

Launch Visual Studio Code, and create folder name CodeWhisperer (if you are a mac user, please acknowledge the below prompt and proceed)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6haxc3ws95602wvg0bz.png)

Go ahead and authenticate with your BuilderID as per the below instructions to connect to the Builder ID 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amcnigvmwh0un54f3xsr.png)

### Amazon CodeWhisperer usage instructions <a name="usage"></a>
* To activate CodeWhisperer, simply place your cursor after a comment or line of code and press Enter. 
* Use the left/right arrow keys to browse through multiple suggestions.
* Accept a suggestion by pressing Tab or discard it by pressing Esc or typing a character. 
* After accepting or writing new code, press Enter again for the next line of suggested code. 
* If the suggestion is not appearing, you can manually trigger Amazon CodeWhisperer by clicking Option + C on MacOS or Alt + C on Windows.

### Getting started with python coding <a name="python"></a>
* Install Python Extensions for Visual Studio Code and start coding.
* Follow the video to explore lists and operations in python, generate Fibonacci series with the specified number of terms as input.
{% embed https://youtu.be/q4odwHC_txU %}

### AWS re:Invent 2024 <a name="reinvent"></a>
The following enhancements were announced in AWS re:Invent 2023 which is available in preview for Visual Studio
* Support for CloudFormation (YAML, JSON)
* AWS CDK (TypeScript, Python)
* Hashicorp Terraform (HCL)

### Pricing <a name="pricing"></a>
Amazon CodeWhisperer is free for individuals and billed via Amazon Q at $19/user/month for professionals under professional tier. The professional tier offers access to Amazon Q Code Transformation, which speeds up language upgrades to Java 17, as well as Amazon Q feature development, assisting you in devising a strategy for incorporating a new feature.
Refer [CodeWishperer pricing](https://aws.amazon.com/codewhisperer/pricing/) for more details.

### Resources <a name="reflinks"></a>
* [Amazon CodeWhisperer](https://aws.amazon.com/codewhisperer/) 
* [Getting started with Amazon CodeWhisperer](https://aws.amazon.com/codewhisperer/resources/#Getting_started/) 
* [Amazon CodeWhisperer user guide](https://docs.aws.amazon.com/codewhisperer/)
* AWS re:Invent 2023 Videos 
  * [AWS re:Invent 2023 - Boost your productivity with AWS Toolkits and Amazon CodeWhisperer](https://www.youtube.com/watch?v=23xghoCEe6M)
  * [AWS re:Invent 2023 - Best practices for Amazon CodeWhisperer](https://www.youtube.com/watch?v=F_dSkRHCXBc)
* [Best Practices for prompt engineering with Amazon CodeWhisperer](https://aws.amazon.com/blogs/devops/best-practices-for-prompt-engineering-with-amazon-codewhisperer/)
* [Look beyond code coverage with Amazon CodeWhisperer
](https://aws.amazon.com/blogs/devops/looking-beyond-code-coverage-with-amazon-codewhisperer/)

### Conclusion <a name="conclusion"></a>
Go ahead and discover how Amazon CodeWhisperer revolutionises application development with its AI-powered coding assistance. Apply your learnings into practice to see how CodeWhisperer provides real-time code suggestions, enhances security by scanning for vulnerabilities, and improves efficiency by identifying code resembling open-source training data.