Simplifying AWS Lambda Development with Amazon CodeWhisperer: Streamlining Serverless Function Development

Sudarkodi Muthiah
5 min readDec 24, 2023

--

Amazon CodeWhisperer

Introduction

In this blog 📔, we’ll explore how Amazon CodeWhisperer, an AI-powered coding companion, streamlines the development and management of an AWS Lambda function. We’ll leverage CodeWhisperer’s intelligent suggestions, automated code generation, and real-time feedback to simplify the process.

Amazon CodeWhisperer

📀Amazon CodeWhisperer is a general-purpose, machine learning-powered code generator that provides code recommendations to developers in real-time.

📀As developers write code in AWS services, such as AWS cloud9 and AWS Lambda, CodeWhisperer automatically generates suggestions based on existing code and comments. The personalized recommendations can vary in size, and scope, ranging from a single-line comment to fully formed functions.

📀CodeWhisperer supports multiple programming languages and multiple IDEs such as VSC and IntelliJ.

To learn more about Amazon CodeWhisperer and access detailed information, I recommend checking the official AWS documentation here. 💡 What is CodeWhisperer? — CodeWhisperer (amazon.com)

Prerequisites

Before proceeding with the use case, make sure you have the following prerequisites in place:

🧿AWS Cloud9: Set up an AWS Cloud9 development environment.

🧿IAM Permissions: Ensure that your AWS account has the necessary IAM permissions to create and manage AWS Lambda functions, S3 buckets, and other required resources.

🧿AWS CLI: Install and configure the AWS Command Line Interface (CLI) on your development machine or AWS Cloud9.

🧿CodeWhisperer Integration: Ensure that CodeWhisperer is enabled and integrated with your development environment, such as AWS Cloud9 or the Lambda console.

Use Case

🎡We write an AWS Lambda function to create an S3 bucket and upload an object to the bucket in AWS Cloud9. With CodeWhisperer’s automated code generation, we generate AWS CLI commands in Cloud9 to deploy the Lambda function effortlessly and run it in the AWS console.

🎡By utilizing the AWS S3 console, we review the objects uploaded to the S3 bucket. Using CodeWhisperer within the Lambda console, we update the function to enable object deletion from the S3 bucket.

🎡Furthermore, CodeWhisperer assists us in enabling versioning on the S3 bucket. Finally, we deploy and test the enhanced Lambda function, ensuring its successful execution.

Flow Diagram

Simplifying AWS Lambda development with CodeWhisperer

Let’s begin by examining the steps to develop the mentioned use case.

  1. Sign in to the AWS Cloud9 console.
  2. Resume Auto-suggestions

We enable the Resume Auto-suggestions option to receive code suggestions in an AWS Cloud9 instance.

3. Write comments

CodeWhisperer can generate code from comments. During code development, Write comments to check the S3 bucket exists. CodeWhisperer can use these comments to suggest code snippets that accomplish the desired tasks.

4. Accept suggestions

Accept the CodeWhisperer suggestions to create an AWS Lambda function (addObjects.py) that will create an Amazon S3 bucket and upload objects to the bucket.

The below snippets show the code recommendations generated by Amazon CodeWhisperer to create an Amazon S3 bucket and upload objects to the bucket.

5. Use Suggestion

To deploy the Lambda function, We use the CodeWhisperer suggestions for bash and AWS CLI commands.

6. Review Lambda Code

Review the Lambda function on the console and create a test event.

7. Create an S3 bucket

Run the Lambda function to create the S3 bucket and upload objects to the bucket.

8. Review content in S3

Review the S3 bucket and its contents.

9. Enable suggestions in Lambda

To test CodeWhisperer suggestions in Lambda, enable CodeWhisperer on the Lambda console and use suggestions to update the Lambda function to delete an object from the created S3 bucket.

From the Tools menu, enable Amazon CodeWhisperer Code Suggestions. After the comment, select Suggest Code Snippet from the Tools menu.

We deploy the updated Lambda function to delete an object in Amazon S3 and run the function. We then review the updates in the S3 bucket.

10. Update the code to enable versioning on the S3 bucket

Using CodeWhisperer suggestions, update the Lambda function to enable versioning on the S3 bucket.

11. Check versioning on S3

Deploy and run the lambda function, and then check the bucket to ensure that the versioning is enabled.

🎯Through CodeWhisperer’s intelligent suggestions and automated code generation, the entire process is streamlined, saving time and enhancing productivity in AWS Lambda development.

To access the detailed 🔈step-by-step guide🔈 for the use case mentioned, please refer to the GitHub repository here: https://github.com/Sudarkodi-Muthiah-repo/12weeksAWSworkshopchallenge/blob/main/Week11/Simplifying_AWS_Lamda_Development_with_Amazon_CodeWhisperer.md

Conclusion

🎉By harnessing the power of Amazon CodeWhisperer, we simplify the development, deployment, and management of AWS Lambda functions for interacting with Amazon S3 buckets. Its AI-driven suggestions, automated code generation, and real-time collaboration features enable developers to write efficient and error-free code, speeding up the development lifecycle and enhancing productivity in AWS Lambda projects.

✨CodeWhisperer boosts productivity and enables developers to focus on building innovative serverless applications. By adopting CodeWhisperer, developers can unlock their full potential and achieve optimal efficiency in their serverless development journey.

#aws #codewhisperer #Lambda #serverless #awscloud #cloudcomputing #12weeksawsworkshopchallenge #aicodingcompanion

--

--