AI/ML, AWS, Cloud Computing

3 Mins Read

Optimal Approaches to Prompt Engineering with Amazon CodeWhisperer

Voiced by Amazon Polly


Amazon CodeWhisperer, with its innovative approach to AI-powered coding assistance, has established itself as a cornerstone in software development. Harnessing the capabilities of artificial intelligence, Amazon CodeWhisperer aids developers by delivering code recommendations based on natural language comments and surrounding code. However, unlocking the full potential of Amazon CodeWhisperer requires mastery of the nuanced art of prompt engineering. This blog explores the best practices for prompt engineering in Amazon CodeWhisperer, equipping developers to refine their coding processes and elevate productivity.

The Essence of Prompt Engineering

Prompt engineering involves the meticulous refinement of interactions with large language models (LLMs) to obtain outputs that are accurate and highly relevant. In the Amazon CodeWhisperer context, prompt engineering entails crafting comments that effectively guide the tool, ensuring the generation of high-quality code.

Let’s delve into the best practices that empower developers to leverage the capabilities of Amazon CodeWhisperer fully.

Clarity and Brevity:

When creating prompts for Amazon CodeWhisperer, prioritize clarity and brevity. Ambiguous or needlessly complex comments can lead to misinterpretation. Utilize specific comments about the task, such as “develop a function to manage user authentication,” steering clear of vague statements.

Strategic Use of Multiple Comments:

Using multiple comments, strategically breaking down a complex task into manageable steps is achievable. Each comment can address a specific facet of the problem, allowing Amazon CodeWhisperer to generate code incrementally. This method ensures clarity is maintained and that each task element is well-defined.

Leveraging Surrounding Code Context:

Amazon CodeWhisperer surpasses the realm of comments, considering the context provided by surrounding code. Embed relevant information in comments while ensuring the existing code offers additional cues. The tool analyzes this broader context to generate code recommendations aligned with the overall structure of the project.

Cross File Context:

The ability of Amazon CodeWhisperer to comprehend context across different files is a game-changer. Capitalize on this feature by referencing functions or components from one file in prompts for another. This cross-file context empowers developers to maintain consistency and coherence across their codebase.

Chain of Thought Prompting:

Embrace a chain of thought when structuring prompts. Connecting multiple prompts helps Amazon CodeWhisperer grasp the sequential steps of a complex coding task. This technique guides the tool through the logical flow of the problem, resulting in more accurate and contextually relevant code recommendations.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Best Practices with Examples

Let’s delve into practical examples to illustrate the effective implementation of these best practices in Amazon CodeWhisperer:

Example 1: Clarity and Brevity

Example 2: Strategic Use of Multiple Comments

Example 3: Leveraging Surrounding Code Context

Example 4: Cross File Context

Example 5: Chain of Thought Prompting


Mastering prompt engineering is a skill that developers can cultivate to enhance their interaction with Amazon CodeWhisperer. By adhering to these best practices, developers can ensure clear communication with the tool, guiding precise and relevant code generation. As Amazon CodeWhisperer continues to play a pivotal role in developers’ toolkits, adept prompt engineering undoubtedly leads to increased productivity and streamlined software development processes.

Drop a query if you have any questions regarding Amazon CodeWhisperer and we will get back to you quickly.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, Microsoft Gold Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, and many more.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.


1. Can I use multiple comments in a prompt?

ANS: – Yes, using multiple comments strategically is a recommended practice in prompt engineering. It allows developers to break down complex tasks into manageable steps, providing clarity to Amazon CodeWhisperer and ensuring incremental code generation.

2. How can I analyze and select the optimal code recommendation from Amazon CodeWhisperer?

ANS: – Developers can analyze and select the optimal code recommendation by reviewing the suggestions provided by Amazon CodeWhisperer. Consider factors such as correctness, efficiency, and alignment with project requirements to choose the most suitable code snippet.

3. Does Amazon CodeWhisperer generate unit tests as well?

ANS: – Yes, Amazon CodeWhisperer can generate unit tests. By providing prompts with cross-file context, developers can guide Amazon CodeWhisperer to create unit tests for the functions or code snippets it generates.

WRITTEN BY Rohit Lovanshi

Rohit Lovanshi works as a Research Associate (Infra, Migration, and Security Team) at CloudThat. He is AWS Developer Associate certified. He has a positive attitude and works effectively in a team. He loves learning about new technology and trying out different approaches to problem-solving.



    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!