Amazon CodeWhisperer coding in Python with VS Code: Get started with generative AI on AWS - Part 2
Tags: aws, machinelearning, generativeai, tutorial
Published: 2023-05-09 15:35:11

## Generative AI - creating coding suggestions in Python

As a data scientist, data analyst, developer, consultant or student you may have work or passion projects you would like to build quickly - let me introduce you to your new AI coding companion Amazon CodeWhisperer.

Let's increase your developer productivity, help you get started with generative AI, spend less time debugging code and tick the box where it is user-friendly and ready for organizations to use in a secure environment.

### Learning Objectives

In this lesson you will learn the following:

* What is Amazon CodeWhisperer?
* What are the benefits?
* What are the common use cases?
* How do I install Amazon CodeWhisperer for work?
* How do I install Amazon CodeWhisperer for personal use?

### What is Amazon CodeWhisperer?

Amazon CodeWhisperer is a [machine learning-powered coding companion](https://aws.amazon.com/blogs/aws/amazon-codewhisperer-free-for-individual-use-is-now-generally-available/) that suggests coding recommendations as you type comments in real-time using natural language processing to help you code faster.

VP of Databases, Analytics and ML, [Dr Swami Sivasubramanian](https://aws.amazon.com/blogs/machine-learning/announcing-new-tools-for-building-with-generative-ai-on-aws/) announced the general availability of Amazon CodeWhisperer last month on 13 April 2023.

The architecture of Amazon CodeWhisperer is based on large language models (LLMs) trained on [billions of lines of code](https://aws.amazon.com/codewhisperer/faqs/)

### What are the benefits?

* Free to use for individual developers 

* Available in all AWS regions

* Provides 50 security scans per user per month for individual use and 500 scans per user per month under professional tier 

* Provides data protection, is provided by the AWS Shared Responsibility model

* [Security best practices with Amazon CodeWhisperer](https://docs.aws.amazon.com/codewhisperer/latest/userguide/security-best-practices.html)

* Provides coding suggestions for many [languages] (https://docs.aws.amazon.com/codewhisperer/latest/userguide/language-ide-support.html#language-support) such as Ruby, Go, PHP, C++, C, Shell, Scala, Rust, Kotlin, SQL. The languages with the most support are Java, Python, JavaScript, TypeScript and C#.

### What are the common use cases?

To help increase developer productivity, some use cases may include:

* Providing a secure AI powered coding companion that will provide coding suggestions

* Help to write less code for a nested SQL query

* Help to write a repeatable function in Python

* Management Consultants need to spend less time coding and more customer-facing time with their customer. [Accenture](https://aws.amazon.com/blogs/machine-learning/how-accenture-is-using-amazon-codewhisperer-to-improve-developer-productivity/) is a case study for early adoption.

### Pre-requisites

AWS recommends and provides some [important](https://docs.aws.amazon.com/codewhisperer/latest/userguide/whisper-setup-indv-devs.html) tips here:

* Disable any existing VS code extensions
* Install the latest version of VS Code
* Install the latest version of AWS Toolkit

In the image below, I have to disable other VS code extensions and update to the latest version of AWS Toolkit.

![Toolkit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z5repjk8xho8sy35vgv.jpg)

 Click **Connect to AWS** and select **click here**.

![connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9txw2i8fvjuput1fbpmn.jpg)

### Tutorial 1: Install Amazon CodeWhisperer for individual use with IDE VS Code for Python

You may locate the instructions for installing Amazon CodeWhisperer [here](https://docs.aws.amazon.com/codewhisperer/latest/userguide/whisper-setup-indv-devs.html)

Step 1: To get started you will have to [create a builder ID](https://docs.aws.amazon.com/signin/latest/userguide/create-aws_builder_id.html) which is your **personal profile** for authentication as an individual user. You do not need to have an existing AWS account.

Whether you are a data scientist, data analyst, student or just working on other personal projects you will need to have a Builder ID before you can use Amazon CodeWhisperer.

Step 2: Use a personal email address to sign up or sign-in with an AWS Builder ID


![builder ID](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofudkdojpgfnoy36x678.jpg)

Step 3: Copy the code and proceed to the login.

![copy code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jp1r4heg675pyatdfeq.jpg)

Step 4: Enter your email address and full name.



![name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1knapngv8pazzqy1dwb.jpg)

Click allow access of AWS Toolkit to VS Code.


![allow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eobw21r3sno1vsz1i0go.jpg)

Step 5: You will receive verification that your email address was verified. Create a password and confirm your password.


![password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07oeropup14q3mqlyvsn.jpg)


Step 6: Enter the verification code that was emailed to your personal email address.


![veri](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj5x7cl5k42hf6nd24m9.jpg)


Step 7: You will receive information that you have been granted access and the authentication process was successful.


![successful](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzg6ydlkgfc2wkajr3dl.jpg)

Step 8: Connect to AWS and sign-in with your AWS Builder ID.


![sign in](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sroazg7slkbnv78nwnp3.jpg)

Step 9: Once your AWS Builder ID is connected in AWS Toolkit for VS Code, open the side-bar menu to **Code Whisperer**.


![open](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ga8yyp9vhral0ympkar.jpg)

Step 10: Click **Start** on the bottom right-handside corner.

Step 11: Go to **File**, New File and select Python.

You may start typing a few words in Python e.g. import pandas

You may accept the code suggestion by clicking tab on your keyboard.

Step 12: Import Python libraries


![import pandas](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jw5l0ob7xuewgj86ai6i.jpg)

Step 13: Import Sklearn datasets


![datasets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qtyxjnfeu9fopf2h2t7.jpg)

Step 14: Import the library that includes the functions to perform PCA
![pca](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2owwyylzhq5g52mz7gk.jpg)

You may also watch this screencast 'Getting started with Amazon CodeWhisperer with VS Code' by Amazon Web Services

{% embed https://www.youtube.com/watch?v=rHNMfOK8pWI %}

### How would I use Amazon CodeWhisperer in my organization?

You will need to contact your IT Help Desk to request that an administrator download and install VS Code and then follow the steps [here](https://docs.aws.amazon.com/codewhisperer/latest/userguide/whisper-setup-ent-devs.html) to create credentials for your IAM role from the IAM Identity Center (formerly called single sign-on access) for Amazon CodeWhisperer with your organization.

The pricing for Amazon CodeWhisperer at the professional tier is located [here](https://aws.amazon.com/codewhisperer/pricing/) and billing is charged to your organization AWS account.

### Conclusion

Amazon CodeWhisperer is easy to use and takes about 20 minutes to set up in AWS Toolkit with VS Code IDE for individual use for data science or data analysis using Python. Security scans are enabled to monitor code written by you or that is generated by Amazon Code Whisperer. An AWS Builder ID is your personal profile for authenticating a user with a valid email address.

### References

* [AWS News Blog](https://aws.amazon.com/blogs/machine-learning/announcing-new-tools-for-building-with-generative-ai-on-aws/)

* [Accenture case study](https://aws.amazon.com/blogs/machine-learning/how-accenture-is-using-amazon-codewhisperer-to-improve-developer-productivity/)

* [Amazon CodeWhisperer User Guide](https://docs.aws.amazon.com/codewhisperer/latest/userguide/what-is-cwspr.html)

### This Month - AWS She Builds Global Mentorship application closing 31 May

**AWS She Builds Application**

Apply to participate in the free AWS She Builds Mentorship Program - APJ, EMEA or US. Learn cloud computing ☁️

If you aspire to be a women in tech or interested in learning more about cloud computing, you have until 31 May 2023 to submit your application. Early bird gets the worm! You may apply at this [link](https://aws-shebuildsmentorship-2023.splashthat.com/)

![seh builds](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rw6qhmtdtolkpfwjns9g.jpg)

### Next Month - AWS re:Inforce 2023 on June 13-14 

Are you ready for AWS re:Inforce this year? Join the AWS Community in-person to experience two days of learning, networking with your peers as you further your learning in security, innovation and the latest announcements from the keynotes. 

I hope you will be able to join AWS CISO CJ Moses for his keynote, the AWS Security community next month and register at this [link](https://reinforce.awsevents.com/). There are leadership sessions, partner sessions and expert sessions at the 300 and 400 levels which are focused-learning and interactive sessions.

![next month](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdo13inxldvyl75cie0g.jpg)

You may watch the [keynote](https://www.youtube.com/watch?v=PPunA7tPMyk&list=PL2yQDdvlhXf9kigmpFqzz8B5H5OHvjD_R) from AWS re:Inforce 2022 and also follow the hashtag #AWSreInforce on [Twitter](https://twitter.com/AWSSecurityInfo)

Until the next lesson, happy learning! 😀

## Hello World: Meet Large Language Models

{% embed https://www.youtube.com/watch?v=2C9VTq8cRvo&t=54s %}