Getting Started with MongoDB and AWS Codewhisperer
Rate this tutorial
Amazon CodeWhisperer is trained on billions of lines of code and can generate code suggestions — ranging from snippets to full functions — in real-time, based on your comments and existing code. AI code assistants have revolutionized developers’ coding experience, but what sets Amazon CodeWhisperer apart is that MongoDB has collaborated with the AWS Data Science team, enhancing its capabilities!
At MongoDB, we are always looking to enhance the developer experience, and we've fine-tuned the CodeWhisperer Foundational Models to deliver top-notch code suggestions — trained on, and tailored for, MongoDB. This gives developers of all levels the best possible experience when using CodeWhisperer for MongoDB functions.
This tutorial will help you get CodeWhisperer up and running in VS Code, but CodeWhisperer also works with a number of other IDEs, including IntelliJ IDEA, AWS Cloud9, AWS Lambda console, JupyterLab, and Amazon SageMaker Studio. On the , you can find tutorials that demonstrate how to set up CodeWhisperer on different IDEs, as well as other documentation.
Note: CodeWhisperer allows users to start without an AWS account because usually, creating an AWS account requires a credit card. Currently, CodeWhisperer is free for individual users. So it’s super easy to get up and running.
Installing CodeWhisperer for VS Code
CodeWhisperer doesn’t have its own VS Code extension. It is part of a larger extension for AWS services called AWS Toolkit. AWS Toolkit is available in the VS Code extensions store.
- Open VS Code and navigate to the extensions store (bottom icon on the left panel).
- Search for CodeWhisperer and it will show up as part of the AWS Toolkit.
- Once found, hit Install. Next, you’ll see the full AWS Toolkit Listing
- Once installed, you’ll need to authorize CodeWhisperer via a Builder ID to connect to your AWS developer account (or set up a new account if you don’t already have one).
Navigating code suggestions
With CodeWhisperer installed and running, as you enter your prompt or code, CodeWhisperer will offer inline code suggestions. If you want to keep the suggestion, use TAB to accept it. CodeWhisperer may provide multiple suggestions to choose from depending on your use case. To navigate between suggestions, use the left and right arrow keys to view them, and TAB to accept.
If you don’t like the suggestions you see, keep typing (or hit ESC). The suggestions will disappear, and CodeWhisperer will generate new ones at a later point based on the additional context.
Requesting suggestions manually
You can request suggestions at any time. Use Option-C on Mac or ALT-C on Windows. After you receive suggestions, use TAB to accept and arrow keys to navigate.
Getting the best recommendations
For best results, follow these practices.
- Give CodeWhisperer something to work with. The more code your file contains, the more context CodeWhisperer has for generating recommendations.
- Write descriptive comments in natural language — for example
- Specify the libraries you prefer at the start of your file by using import statements.
- Use descriptive names for variables and functions
- Break down complex tasks into simpler tasks
As with all generative AI tools, they are forever learning and forever expanding their foundational knowledge base, and MongoDB is looking for feedback. If you are using Amazon CodeWhisperer in your MongoDB development, we’d love to hear from you.
We’ve created a special “codewhisperer” tag on our , and if you tag any post with this, it will be visible to our CodeWhisperer project team and we will get right on it to help and provide feedback. If you want to see what others are doing with CodeWhisperer on our forums, the will jump you straight into all the action.
We can’t wait to see your thoughts and impressions of MongoDB and Amazon CodeWhisperer together.