What's new with Amazon CodeWhisperer ?
On 10 May 2023, Senior Principal Technologist at AWS Brian Granger announced extensions to generative AI on Jupyter including:
Jupyter AI, an open-source project to bring generative AI to Jupyter notebooks
Introducing new Jupyter extensions to build, train, and deploy ML at scale
Amazon CodeWhisperer Jupyter extension
For developers, cloud architects, data scientists, data analysts and machine learning engineers in particular this is exciting news allowing JupyterLab users to install Amazon CodeWhisperer to use Python notebooks and also Amazon SageMaker Studio.
You may read all of the Jupyter extensions here.
Learning Objective
You will learn:
- How to install Amazon CodeWhisperer with JupyterLab extension to generate code recommendations within Amazon SageMaker Studio
What's the benefit of using Amazon CodeWhisperer?
You may get started and up and running on a machine learning project and increase your developer productivity with auto-completion, provides code suggestions by learning from code snippets and python comments.
You may also code in other languages such as:
Python, Java, JavaScript, TypeScript, C#, Go, Rust, PHP, Ruby, Kotlin, C, C++, Shell scripting, SQL, and Scala in various IDEs.
There are built-in security scans as you code based on the AWS Shared Responsibility Model.
Amazon CodeWhisperer is free for individual use.
You may read my previous blog post if you would like to know how to install Amazon CodeWhisperer for VS Code IDE.
I recently used Amazon CodeWhisperer to kickstart a personal machine learning project which allowed me to code faster.
By using Amazon CodeWhisperer in VS code editor, I was able to complete exploratory data analysis (EDA) in python, I simply typed words into VS code editor and asked a question like a friend using natural language. EDA was completed within 15 minutes and learned about my intent by reading my python comments and making the next suggestion in the data analytics workflow.
Get code recommendations for Amazon SageMaker Studio
Amazon SageMaker Studio launched in 2019 as an IDE using JupyterLab
to allow data science teams to collaborate on the end to end data science workflow which includes build models, train models, fine-tune hyper parameters, debug, deploy, and monitor model drift.
On the 10 May 2023, there were new announcements
You may now receive real-time code recommendations from Amazon CodeWhisperer as you code and build your machine learning pipeline within Amazon SageMaker Studio.
Pre-requisites
Creating your first IAM admin user and User group in your AWS account
You may read the following blog to onboard Amazon SageMaker Domain.
Add the Amazon CodeWhisperer-related permissions to your SageMaker execution role (e.g. Amazon SageMaker FullAccessrole)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CodeWhispererPermissions",
"Effect": "Allow",
"Action": ["codewhisperer:GenerateRecommendations"],
"Resource": "*"
}
]
}
Tutorial: Add the CodeWhisperer-related permissions to your SageMaker execution role.
For this tutorial please follow the steps from the Amazon CodeWhisperer Developer Guide.
Step 1: Login to your AWS account as an Admin User and choose your preferred AWS region e.g. Asia Pacific Sydney (ap-southeast-2).
Step 2: Navigate to the IAM dashboard.
Step 3: Create an IAM policy that contains the following actions to enable Amazon CodeWhisperer for Amazon SageMaker Studio role.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CodeWhispererPermissions",
"Effect": "Allow",
"Action": ["codewhisperer:GenerateRecommendations"],
"Resource": "*"
}
]
}
Navigate to Policies on the left-handside menu.
Step 4: Click Create policy.
Step 5: Click json.
Step 6: Copy the new IAM policy into the json statement and click Next.
Step 7: Provide a policy name e.g. Attach_Amazon_CodeWhisperer_to SageMaker_Studio and click Create policy.
The policy was successfully created.
You may inspect the policy.
Navigate to IAM and click Roles, search for 'Sagemakerfullaccess role' and check if there are any policies already attached.
Step 8: Navigate to Policies and search for policy 'Attach_Amazon_CodeWhisperer_to SageMaker_Studio' and attach the following IAM entity:
SageMakerfullaccess
Step 9: Navigate to the Amazon SageMaker dashboard and on the left-handside menu click Getting Started and on the right select Create a role.
Step 10: Enter the following details such as providing a role name with the pre-fix of SageMaker. e.g. DataScientist, MLEngineer
DataScientist_SageMaker
You may also provide a short description of the role e.g. create a role to enable Amazon CodeWhisperer recommendations for Amazon SageMaker Studio.
Retain the other default settings and click Next.
Step 11: Configure the role by selecting the ML activities.
You may select more activities or de-select the ML activities that you do not require.
Step 12: Scroll down and enter the name of one of your Amazon S3 buckets to store your training and test data. Click Next.
sagemaker--<AWS account number
Step 13: In the search bar, start typing the name of the IAM policy that was created in Step 7.
Attach_Amazon_CodeWhisperer_to SageMaker_Studio
Check the box of the policy and click Next.
Step 14: Inspect and review the role details.
Review the additional policy attached to the SageMaker execution role and click Submit.
Step 15: The Sagemaker_DataScientist_SageMaker role was successfully created and you may view the role in IAM.
You can see that this new role has an additional policy attached to enable Amazon CodeWhisperer to be used under the SageMaker execution role for Amazon SageMaker Studio.
Step 16: Enable Amazon CodeWhisperer within Amazon SageMaker Studio
Select Studio on the left-handside menu and click Open Studio.
Step 17: In Amazon SageMaker Studio, click Open Launcher.
Step 18: Under the heading 'Utilities and file', click System terminal.
Step 19: Copy the code into terminal:
conda activate studio
pip install amazon-codewhisperer-jupyterlab-ext
jupyter server extension enable amazon_codewhisperer_jupyterlab_ext
conda deactivate
restart-jupyter-server
The installation process will take a few seconds to complete.
Step 20: Navigate to the Launcher homepage and select Create Notebook.
I received the following notification message.
Step 21: Close the Amazon SageMaker Studio session.
Refresh your browser and navigate to Studio and click Open Studio and wait for Amazon SageMaker Studio to open.
Under the notebook you will be able to see a tick against CodeWhisperer to confirm that code recommendations are enabled for the code cells.
Step 22: Launch Studio again and you will be taken to JupyterLab which will open the last notebook and start typing Python code into the code cells to generate code recommendations.
Reference
Until the next lesson, happy learning! 😀
Build on Generative AI - Using your Python scripts in Sagemaker
You may be interested to learn more from to change your Python scripts to run on SageMaker Training? 🦅Join guest Giuseppe Angelo Porcelli, along with cohosts Darko Mesaroš & Emily Webber to learn more on Build on Generative AI
Last week - AWS re:Inforce 2023
You may be interested to learn more about Amazon Bedrock, foundation models and Generative AI from AWS re:Inforce announcements last week. You may watch the keynote from AWS CISO CJ Moses, break-out sessions and leadership sessions here
Top comments (0)