What is CodeWhisperer? - CodeWhisperer

CodeWhisperer's features are becoming a part of Amazon Q Developer. Learn more

What is CodeWhisperer?

Note

The fastest way to start using CodeWhisperer is to authenticate with AWS Builder ID as an individual developer. You don't need an AWS account to do this.

Amazon CodeWhisperer is a general purpose, machine learning-powered code generator that provides you with code recommendations in real time. As you write code, CodeWhisperer automatically generates suggestions based on your existing code and comments. Your personalized recommendations can vary in size and scope, ranging from a single line comment to fully formed functions.

When you start typing out single lines of code or comments, CodeWhisperer makes suggestions based on your current and previous inputs.

In the image below, a user has started to type out a line of code. Based on the input, CodeWhisperer has generated suggestions to complete the line. The user can cycle through the suggestions using the arrow keys.

alt_text

In the example below, in Java, a user inputs a comment. CodeWhisperer suggests a function signature.

After the user accepts that suggestion, CodeWhisperer suggests a function body.

An example of a function generated from a comment.

Block completion is used to complete your if/for/while/try code blocks.

In the example below, in Java, a user enters the signature of an if statement. The body of the statement is a suggestion from CodeWhisperer.

An example of the block completion feature.

CodeWhisperer can also scan your code to highlight and define security issues.

In this example using Python and JetBrains, the user has written code that would write unencrypted AWS credentials to a log; a bad security practice.

Fortunately, the user has also run a security scan. CodeWhisperer has identified the problem, and raised an alert.

alt_text

For information about which programming languages CodeWhisperer supports, see Language support.

CodeWhisperer in action

This section demonstrates how CodeWhisperer can help you write a complete application. This application creates an Amazon S3 bucket and a Amazon DynamoDB table, plus a unit test that validates both tasks.

Here, CodeWhisperer helps the developer choose which libraries to import. Using the arrow keys, the developer toggles through multiple suggestions.

An example of the block completion feature.

Here, the developer enters a comment, describing the code they intend to write on the next line.

CodeWhisperer correctly anticipates the method to be called. The developer can accept the suggestion with the tab key.

alt_text

Here, the developer prepares to define constants.

CodeWhisperer correctly anticipates that the first constant will be REGION and that its value will be us-east-1, which is the default.

alt_text

Here, the developer prepares to write code that will open sessions between the user and both Amazon S3 and DynamoDB.

CodeWhisperer, familiar with AWS APIs and SDKs, suggests the correct format.

alt_text

The developer has merely written the name of the function that will create the bucket. But based on that (and the context), CodeWhisperer offers a full function, complete with try/except clauses.

Notice the use of TEST_BUCKET_NAME, which is a constant declared earlier in the same file.

alt_text

The developer has only just begun to type in the name of the function that will create a DynamoDB table. But CodeWhisperer can tell where this is going.

Notice that the suggestion accounts for the DynamoDB session created earlier, and even mentions it in a comment.

alt_text

The developer has done little more than write the name of the unit test class, when CodeWhisperer offers to complete it.

Notice the built-in references to the two functions created earlier in the same file.

The developer has only just begun to type in the name of the function that will create a DynamoDB table. But CodeWhisperer can tell where this is going.

Notice that the suggestion accounts for the DynamoDB session created earlier, and even mentions it in a comment.

alt_text

Based only on a comment and the context, CodeWhisperer supplies the entire main function.

alt_text

All that's left is the main guard, and CodeWhisperer knows it.

Based only on a comment and the context, CodeWhisperer supplies the entire main function.

alt_text

Finally, the developer runs the unit test from the terminal of the same IDE where the coding took place.

alt_text