Amazon CodeWhisperer is a Machine learning-powered service trained on billions of lines of code. It generates code recommendations and helps to improve developers’ productivity. CodeWhisperer automatically generates code recommendations ranging from code snippets to full functions based on the comments and code written in natural languages.
Features of Amazon CodeWhisperer
- Get more done faster: It reduces the coding time and accelerates code-building tasks with unfamiliar APIs.
- Code with confidence: You can easily review and add attribution using CodeWhisperer based on the open-source projects repository URL and License.
- Enhance code security: It scans your code to detect vulnerabilities that are hard to find, such as those that don’t meet security or crypto library best practices that are hard to find, and gives you code recommendations to remediate them immediately.
This blog mainly focuses on how to set up Amazon CodeWhisperer with AWS Lambda and activate code recommendations, followed by one example.
- Cloud Migration
- AIML & IoT
Lambda is a serverless computing service that runs code in response to events without provisioning or managing servers. You just need to write your code and supply it to runtime that lambda supports. AWS Lambda runs your code on compute infrastructure and performs all management tasks like server and operating system maintenance, capacity provision, scaling, and logging.
AWS Lambda runs your code in response to the event, and you pay only for the compute time you consume to run the code.
Set up Amazon CodeWhisperer with AWS Lambda
Amazon CodeWhisperer can be integrated with AWS Lambda to get code recommendations for the comments and code written in the AWS Lambda function.
You can integrate Amazon CodeWhisperer with AWS Lambda using the following steps.
Step 1: Create a lambda function. Add Function Name and Runtime. Create a lambda function. Add Function Name and Runtime.
Step 2: Click on “Change default execution role” and select a role to assign permission to access Amazon S3. Click on “Create Function”
Permission attached to IAM Role
Step 3: Open the Function, go to “Tools,” and select “Amazon CodeWhisperer Code Suggestions.” This will activate the CodeWhisperer code recommendation for the AWS Lambda function.
Step 4: Another way to activate Amazon CodeWhisperer is to click on “+” and select “Preferences.”
Step 5: Go to “User Settings” and enable “Amazon CodeWhisperer Code Suggestions.”
Code Recommendation to create an S3 bucket in the AWS Lambda function
Here is an example lambda function to create an Amazon S3 bucket using Python code. Once you type the comment like “#import json python library” and click “Alt+c”, Amazon CodeWhisperer will generate a code recommendation, and you will able to add code to the Function
The below snippets will show the code recommendations generated by Amazon CodeWhisperer to create an Amazon S3 bucket.
Amazon CodeWhisperer service generates code recommendations using the comments and code written in natural language. It is a machine learning-based code generator service that helps to improve developers’ productivity. One can easily activate Amazon CodeWhisperer with AWS Lambda and get code recommendations.
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
CloudThat is an official AWS(Amazon Web Services) Advanced Consulting Partner and Training partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, Amazon QuickSight Service Delivery Partner, AWS EKS Service Delivery Partner, and Microsoft Gold Partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
WRITTEN BY Rashmi D