AWS CodeWhisperer is a machine learning coding companion that suggests code recommendations in real time to enhance developer efficiency and productivity. Code recommendations are based on natural language which can range from single-line comments, the code you write, or fully formed functions.
CodeWhisperer automates the process of code analysis, detecting potential problems at an early stage and elevating the overall quality of code. This tool simplifies the code review process, facilitating quicker development cycles and ultimately leading to improved software dependability.
Benefits of Using CodeWhisperer
AWS CodeWhisperer has been trained on billions of lines of code. It can understand the comments written in natural language and based on that it can generate multiple code suggestions in real time.
It suggests the logical blocks of code or entire functions directly in the code editor. Generated code is similar to how you write code, matching your style and naming convention. CodeWhisperer has been optimized for the most used AWS APIs such as Amazon EC2, Amazon S3, and AWS Lambda.
CodeWhisperer provides AI code suggestions for multiple programming languages and IDEs
Visual Studio (VS) Code, JetBrains IDEs, AWS Cloud9, WebStorm, PyCharm, JupyterLab and Amazon SageMaker Studio.
Supercharge Your Programming Productivity with CodeWhisperer
CodeWhisperer is a coding companion designed to enhance developer efficiency and productivity. It supports a wide range of programming languages and easily integrates with popular IDEs.
Using CodeWhisperer, developers can streamline their coding workflow and reduce the need for frequent context switching among the IDE, documentation, and developer forums. With CodeWhisperer providing real-time code recommendations developers can maintain their concentration within the IDE, leading to more efficient completion of coding tasks.
During the preview phase of CodeWhisperer, Amazon conducted a productivity challenge, and participants who utilized Amazon CodeWhisperer demonstrated a 27% higher in completing tasks successfully with a great average speed improvement of 57% compared to those who did not use CodeWhisperer.
These stats show a significant boost in developer productivity which allows you to deliver high-quality code more faster and effectively.
In summary, AWS CodeWhisperer stands as a robust code analysis solution capable of enhancing both the integrity and safety of your codebase. It serves as an excellent choice for developers seeking a versatile code analysis tool equipped with an extensive array of functionalities and seamless integrations.
Prerequisite Steps to Install CodeWhisperer in Your Environment
In the following demonstration, we will launch and interact with the basic components required to use CodeWhisperer.
In this demo, we will go with Visual Studio Code to create an AWS Builder ID and show how to connect VS code to CodeWhisperer.
(1) Open your VS Code and head to the Extensions marketplace. Search for “AWS Toolkit” and install the official extension.
(2) After installing “AWS Toolkit” Connect to AWS to add a new connection. Select CodeWhisperer in connection to sign in with AWS Builder ID
(3) To get started you will have to create a builder ID which is a personal profile for authentication as an individual user.
(4) Select Sign up or Sign in to open the AWS Builder ID login page. Use your personal email ID to sign up or sign in with AWS Builder ID
(5) Copy the code and proceed to the login.
(6) In AWS Builder ID login page enter your email address and full name.
(7) Enter the verification code that will be sent to your email address.
(8) You will receive verification that your email address was verified. Create a new password and confirm your password.
(9) You will receive the notification that your authentication process was successful and access has been granted.
(10) Connect to AWS and sign in with your AWS Builder ID.
(11) When AWS Builder ID is connected in AWS ToolKit for VS Code, open the sidebar menu to CodeWhisperer and click on start button to enable codewhisperer in VS Code.
How CodeWhisperer Works: Simplifying Code Generation
Now we will generate a code of lambda function using CodeWhisperer in VS code by implementing certain examples :
Example 1:Generating Timestamps for S3 Object Uploads in AWS Lambda
Let’s begin by manually setting up both an S3 bucket and a Lambda function within the AWS environment.
In the same breath, we’ll introduce CodeWhisperer a valuable tool that can automatically generate full code and offer line-by-line recommendations for your Lambda functions.
(1) Create an S3 bucket and lambda function setting the runtime as the latest version of Python, and make sure to give the appropriate permission of S3 to the lambda function role.
(2) In VS code editor start writing a few lines of code and in single line comment mention the requirement that needs to be achieved through the lambda function as shown below, that it will generate the full function code recommendations.
(3) Here we are telling to upload an object to the S3 bucket which generates a timestamp using the generated key.
(4) You can see above that CodeWhisperer generates the entire lines of code in real time by simply entering the one-line comment, Press the tab to complete the entire code and you will see that Codewhisperer completes the full function code.
Replace your bucket name and key in the function code.
(5) Copy this generated code by CodeWhisperer to lambda function code in lambda source code.
(6) Configure the test event to test the function code. In the execution result you will see the status code of 200 and body message.
By invoking the lambda function S3 object is also uploaded to S3 bucket with the current timestamp name and body massage.
Example 2:Sending SQS Messages and Triggering SNS Notifications with AWS Lambda
Initially, we will manually create a Lambda function, an SQS Queue, and SNS Topics. These components will form the basis for our architecture, enabling the Lambda function to send messages to the SQS Queue while simultaneously triggering SNS notifications to users via email subscriptions.
Here also we will define a CodeWhisperer to provide code recommendations within our Lambda function source code.
(1) Create a standard SQS Queue and SNS topics with email subscription in place and leave all default settings in AWS Console.
(2) Create a Lambda function with runtime set as the latest version of Python, also make sure to assign the appropriate permission of SQS and SNS to lambda function role.
(3) Same as the above example start writing a few lines of code and through a single line comment CodeWhisperer will generate full function code recommendation.
(4) Press tab to complete the entire lines of code and you will see that Codewhisperer completes the full function code.
Replace the queue name and SNS topic arn in the function code.
(5) Upon invocation, Lambda function performs a dual action: it dispatches a message to an SQS Queue while simultaneously triggering a notification from an SNS topic, ensuring that emails are promptly delivered to users.
In this article, we have seen how AWS CodeWhisperer represents a significant leap forward in developer productivity and code quality within the AWS ecosystem. With its ability to understand natural language comments and generate real-time code suggestions, it empowers developers to work more efficiently and effectively.
The time and effort saved in code generation and the assurance of best practices can make a substantial difference. So, dive in, explore its capabilities, and witness first hand how CodeWhisperer can be your trusted coding companion in the world of AWS development.
About the Author ✍🏻
Varshil Desai is a DevOps Engineer at QloudX who holds an impressive 5 AWS certifications, along with Terraform and Azure certifications.
His main work is in DevOps technology where he specializes in creating automated and efficient solutions for clients.
Despite having just two years of experience in the industry, Varshil has already left a significant impact by developing smart cloud solutions using DevOps automation tools. At the same time, he is also curious to explore AI/ML technology.
Privacy & Cookies Policy
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.