Faster Coding with AWS Code Whisperer
Are you aiming for high code productivity and speed in 2023? Code Whisperer, an ML-powered service helps with recommendations for increased productivity and faster coding. In this blog, I will talk about Code Whisperer, and its features, as well as provide a brief demonstration of how to use Code Whisperer with VS Code.
What is Amazon Code Whisperer?
Amazon Code Whisperer is an ML-powered service provided by AWS. It generates suggestions automatically based on your previous code and comments. Code Whisperer also scans your code (both generated by Code Whisperer and written by you) for vulnerabilities and security issues.
Code Whisperer is trained on various data sources including Amazon.com. While traditional autocompletion tools provide single-word completions, Code Whisperer provides a much better productivity boost by generating entire functions and logical code blocks at a time. Also, Code Whisperer understands the developer’s intent as expressed through plain English comments.
For example, a developer can simply write a comment in plain English such as “Create an EC2 Key Pair using boto3”, using this comment, Code Whisperer recommends the best code snippets directly in IDE. The same example is demonstrated step by step below.
Challenges before Code Whisperer
As there are multiple programming languages, libraries, and frameworks, developers spend a lot of time ensuring that they follow the correct syntax and best practices.
Now, here is where Code Whisperer comes into play. When writing the code, the code whisperer looks for the comments and prior codes. It will use those as input to the ML model and will generate multiple recommendations. This recommendation will automatically appear in the IDE that meets best practices which helps the developers to stay focused.
- VS Code
- Lambda Console
First-class support for AWS APIs
Code Whisperer simplifies the use of AWS services for developers by providing code recommendations for AWS APIs across the most popular services, such as Amazon Elastic Compute Cloud (EC2), AWS Lambda, and Amazon Simple Storage Service (S3). As you write code in your IDE, Code Whisperer analyses the comments, assembles the code using the relevant cloud services and public software libraries for the desired functionality, and then recommends code snippets and even entire functions that meet best practices directly in the IDE.
A reference tracker in Code Whisperer can detect and notify when generated outputs are similar to specific training data. Even though the model has understood how to write code and generates entirely new code based on the learning, an independently generated code recommendation could resemble a unique code snippet in the training data in very rare cases. Code Whisperer makes it easier for you to decide whether to use the code in your project and make the appropriate source code attributions by notifying you when this occurs and providing you with the repository and licensing information.
Code Whisperer has bias detection techniques based on common stereotypes. It includes filters for detecting obvious bias in generated code and removing code recommendations that may be deemed biased and unfair.
Consider a recruiting software that assists hiring managers by automatically shortlisting candidates. The software relies on tie-breaker logic in the event of a tie. An AI model may generate code that favors candidates based on inappropriate parameters while generating a recommendation for this scenario. Code Whisperer can detect bias in recommendations and filter them out before they are shown to the developer.
Security is job number one and as a result, Code Whisperer includes the ability to run scans on your code (both generated by Code Whisperer and written by you) to detect security vulnerabilities. When you select Run Security Scan, Code Whisperer detects and displays the vulnerability.
How to enable Code Whisperer in VS Code
Go to your extensions tab in your left pane and search for AWS Toolkit and install it.
AWS Toolkit Extension
After you’ve installed the aforementioned extension. When the installation is complete, the AWS icon will appear in the left pane.
Open the AWS extension, which should be visible in the left pane. Click on start under Code Whisperer to see connection options to get started with the Code Whisperer. Select and connect with the appropriate option.
How to use Code Whisperer?
This demonstration shows how to use code whisperer to generate an EC2 keypair with boto3.
As previously stated, Code Whisperer reads plain English text, feeds it into the ML model, and then displays a recommendation. In our case, Code Whisperer reads the comment “Create EC2 Key Pair using boto3” and provides step-by-step instructions for creating the key pair.
- Press TAB to accept a suggestion
- Press ALT + C to force a suggestion
- To switch between suggestions, Use the left and right arrow keys to navigate
Security scans are also supported by Code Whisperer. When you select “Run Security Scan”, Code Whisperer detects and displays vulnerabilities. There are no security issues in the code,as shown at the bottom right of the screen.
How to use Code Whisperer for programming languages?
Another short illustration to Sum two numbers in python using Code Whisperer.
In this case, Code Whisperer understands the developer’s intent and automatically shows a recommendation to sum two numbers getting user input from the user and gives a snippet for the recommendation.
We learned about Amazon Code Whisperer, its features, and use cases in this blog. All the developer has to do is stay focused on the IDE and take advantage of real-time contextual recommendations that have already been customized and are ready to use. Based on this, Code Whisperer generates code snippets on the fly and recommends them directly in the IDE, allowing you to code faster and more efficiently.