Code better with Amazon CodeWhisperer
Tags: ai, generativeai, codewhisperer, aws
Published: 2023-09-22 13:24:04

There is a lot of buzz around Generative AI these days. CodeWhisperer is a Generative AI product from AWS that is powered by a Foundation Model trained on billions of lines of code. It speeds up software development by providing contextual code suggestions in real time. 

This blog discusses how AI code generator tools like  CodeWhisperer could change the way software is developed.

## CodeWhisperer - The Code Buddy
CodeWhisperer is your personal Coding Assistant. With CodeWhisperer, you code faster and spend less time writing boilerplate code. 

**Quick Highlights**
- CodeWhisperer currently supports 15 popular programming languages and VS Code & JetBrains IDEs. 
- Support for JupyterLab is also available.
- It is integrated with AWS services like SageMaker Studio, AWS Lambda and Cloud9. 
- Offered in two tiers: Individual (Free) and Professional (Priced).
- To get started, you need an IDE, an AWS Toolkit extension and an authentication method (AWS Builder ID or IAM Identity Center or IAM). 

**Code Examples**
Let's now see some illustrations to witness how CodeWhisperer can boost your coding superpowers. 

> _**Auto-complete:** CodeWhisperer will auto-complete your comments or code as you type._

![auto-complete comment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l5xkjcfurltu3nz1rvy.png)

![auto-complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qujqzx0grpu4k6dqbvst.png)

> _**Get full function code from comments:** You can provide comments as prompts to CodeWhisperer and it will implement the function for you._

![full func](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tasfr8wbbvftsvcy6rgq.png)

> _**Get full function code from function signature:** CodeWhisperer can generate the function body from the function signature._

![signature](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdhnz5wcj76zrl5u74zp.png)

> _**Generate Docstring from Code:** Type the delimiter (/** */) above the method and CodeWhsiperer will generate the docstring for it._

![doctring](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cemtfm5mkr77ff6spv19.png)

> _**Get line-by-line code recommendations:** CodeWhsiperer can provide line-by-line code suggestions and can eventually complete the entire code block._

![line-by-line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vfs0ywlcamxxdp3llw9.png)

> _**Write SQL queries:** CodeWhisperer can suggest Structured Query Language (SQL) code based on comments._

![sql](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3bp59ti6skqtno8wh2u.png)

![sql](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u8bxb6bbrztu6qb6zlk7.png)

> _**Write shell scripts:** CodeWhisperer can help you write code for shell scripts._

![shell script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u98q8n0854stg9rtlx56.png)

![shell script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zp9noowyhlmf8oy7vvhd.png)

> _**Write unit test:** CodeWhisperer can create unit tests to develop testing scenarios for code._

![unit test](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qthldp2k42oqtb0ffcs.png)

> _**Create test data:** CodeWhisperer can help you generate dummy data - just enter the first object as an example, and CodeWhisperer will continue repeating the pattern._

![test](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7tzcil8c7sye0ypee9k.png)

![test](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9czkriga5w5er4xekon.png)

> _**Write Infrastructure as Code:** CodeWhisperer can help you write IaC code using AWS CDK._

![cdk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rp0h95pn8uon2dv5vora.png)

> _**Write code in Jupyter Notebook with SageMaker Studio:** Data Scientists can use CodeWhisperer to get code suggestions directly in the Python notebooks in Amazon SageMaker Studio._

![sage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jz49g5hv1ig5cskstxhs.png)

## CodeWhisperer - More than a Code Generator

Now that we've seen how CodeWhisperer can help you write code faster, let's look at how it's more than just a coding advisor.   

**Helping Developers write Secure Code**
CodeWhisperer helps you deliver secure code by shifting security commitments closer to the developer. CodeWhisperer can run security scans on the code directly in the IDE, allowing developers to detect security vulnerabilities, and get code suggestions to fix them instantly. CodeWhisperer uses Amazon CodeGuru to perform the security scan.

**Inculcating use of Responsible AI**
Does using the code generated by CodeWhisperer subject the organisations to copyright infringement? Fortunately, AWS has a solution to mitigate the legal risk associated with using AI-generated code. CodeWhisperer can flag code for license references (for example, MIT or Apache) ensuring developers don’t inadvertently use licensed code while accepting code suggestions from CodeWhisperer. This empowers developers to use AI responsibly and enables organisations to deliver products to their customers without infringing on the copyright.

**Defusing Privacy Concerns**
When you work with CodeWhisperer, AWS may collect your data for service improvement purposes. So are you putting your organization’s data at risk by using CodeWhisperer? Not really, because CodeWhisperer gives you the control to decide whether or not you want to share your data with AWS. This helps developers and organisations alike to build great software confidently with CodeWhisperer without any privacy concerns.

**Transforming the Developer Role**
The emergence of Generative AI tools like CodeWhisperer opens up the need for a new breed of Developers - those who can code as well as work effectively with AI. Prompt engineering is an emerging job role in the IT industry. Developers can take the leap and become specialists in prompt design, which is about crafting effective prompts to generate desired output from generative AI models. CodeWhisperer can also help developers learn new programming languages more quickly. A Java developer, for example, can easily start writing Python code using CodeWhisperer.

**Removing Technology Barriers**
AI code generators like Amazon CodeWhisperer play an important part in bringing users closer to technology. One of the best things about CodeWhisperer is that it comes with a free tier, making it easily accessible to everyone. 


## Looking Ahead

The future of Generative AI is exciting! It would be interesting to see how Amazon CodeWhisperer evolves over time. For instance, it would be nice to see a chat window and code translation capability in the product in future. 

For now, go ahead and witness firsthand how it changes the coding experience.