So recently the Github Co-pilot was a trend in the development field, it is an amazing technology that turns your plain text comments into code, most of us know about it, and most of us have even used it. I had previously written a blog on it, you can check it out here. I explained how it works and how efficient it can be.
Now for the AWS enthusiasts, Amazon announced the launch of the CodeWhisperer at the re:Mars conference on June 23, 2022!
What is CodeWhisperer?
Amazon CodeWhisperer is an AI Pair Programmer similar to Github Co-pilot, it generates the code based on the plain text comments provided by the developers, it also provides suggestions on writing the comments, and provides multiple code snippets or suggestions to select, It currently supports Java, Javascript, and Python.
The CodeWhisperer is available for a preview currently under AWS Toolkit, so the developers can use it in whatever IDE they are using, like VS Code, PyCharm, AWS Cloud 9 etc.
How Amazon CodeWhisperer works?
According to the AWS website, Amazon CodeWhisperer is a machine learning (ML)–powered service that helps improve developer productivity by generating code recommendations based on their comments in natural language and code in the integrated development environment (IDE).
Source: AWS
My first experience
Since it is available for preview, I had to explicitly join the waitlist and wait for my turn, I then received an email with an access code that I used to enable the CodeWhisperer in my VS Code.
If you want to join the waitlist and play with the CodeWhisperer, signup for the preview here, or you can also directly request access from the VS Code. To do it, follow the below steps.
VS Code AWS Toolkit Navbar
If you have installed AWS Toolkit in your VS Code, you will find AWS Logo on the left navbar as highlighted in the above image, Also make sure that your version is the latest one, and when you click on the logo, you will find a dropdown option named Developer Tools. Here you can find CodeWhisperer, notice the third option which says Request Preview Access.
If you have not installed the AWS Toolkit, go to extensions in the VS Code and install it.
If you request access, you will be redirected to the page where you need to fill in the form to request access.
After filling the above form, you will be notified that you have joined the waitlist. So when it’s your turn, you will get an email that will have an access code. The second option in the navbar is Enter Preview Access Code. When you click on it, you will be shown a text bar, here you can enter the code that you got in the email. See the highlighted sections in the below image.
Once you enter the code, you will see the terms and agreement information. Scroll down and accept the terms and conditions, and you are all set!
Here’s how I tried it out, first of all, the CodeWhisperer takes some time to load once the IDE is started, give it some time, to start the service go keyboard shortcuts and find default key options, I would say it will be easier if you set your own keyboard options.
I created a python file and entered this comment # Function to put an item in dynamoDB table
. One good thing was at the start it gives you code suggestions line by line. For example, once you enter the comment, and call the CodeWhisperer, it gives you the import statement, and then when you press the suggestion keys again, it gives you the function definition, and finally, it gives you the body, also it doesn't stop there, I pressed the suggestion keys again and it gave me the second comment # Function to get an item from dynamoDB table
Also when I typed the comments, it suggested more comments too.
This second time when I called the CodeWhisperer, it gave me the whole function at once, it took the context from the previous code which I had accepted, which is good! and it keeps getting better as you keep using it since your actions will be recorded and used for generating a better context for suggestions.
Another good thing was, that I wrote a wrong comment and it actually suggested a correct comment and gave me the code, also if you see the third highlighted section in the below image, you can see that it didn’t give the whole function body at once, It gave it in bits and pieces, like the return
statement at the end wasn’t the part of the first suggestion.
How is it different from Github Co-pilot?
CodeWhisperer provides some extra features like pausing and resuming the suggestions as and when needed, if you noticed in the above image, the first option in Developer tools is Pause Auto-suggestions. This option is very useful, as you can pause the suggestions as and when needed, and need not disable the extension itself.
The next important one is security, CodeWhisperer lets you run a security scan on the file that is currently open, to ensure that your code is safe and there are no security issues.
What is the drawback?
For one test, I wrote a comment which wasn’t related to any AWS service. # Function to find the second largest number in a list
and Surprisingly, It said no suggestions! However, it gave me suggestions for finding the Prime Number in a list.
The issue is that the model is well trained, but I would say, for a normal code, it might be similar to Github Co-pilot. But it works amazing with the developers who use AWS Services. The suggestions are up to mark with minimal modifications, For generating boilerplate code while working with any AWS Service, the CodeWhisperer comes in very handy, reducing the effort of the developer.
Imagine it this way, when you want to work with some service, you can go to google and search for boto3 documentation and read through and find what you need. CodeWhisperer reduces that effort, you can type the comment here, and based on suggested functions, you can directly go to boto3 documentation and read through for more information instead of finding it.
Alright, that’s it for this blog, Follow me for more articles related to AWS Services.
For more information on CodeWhisperer, check out this link!
Conclusion
Firstly thank you for spending your valuable time on this blog, I really appreciate it.
I hope this blog helped you out in understanding Amazon CodeWhisperer. I would say try it out and you can compare it with Github Co-pilot and choose what’s best for you.
Thanks for reading!