In this blog, I want to show how I was able to set up and use AWS CodeWhisperer for the command line and enhance my productivity.
Just before AWS Re:Invent 2023 there is an amazing update from AWS which allows to use of AI for the command line. Yes it's true that from today we can use AWS CodeWhisperer with AWS CLI with provides
CLI completion, inline documentationand
AI natural language -> to CLI command generation.
Here is the link to the official announcement.
Note: It's still in preview, so specifications about this blog may be subject to change in future.
At this moment codeWhisperer is available only on macOS as per official announcement
CodeWhisperer for command line is available on macOS for all major shells (bash, zsh, and fish) and major terminal emulators such as Terminal, iTerm2, Hyper, and the built-in terminals in Visual Studio Code and JetBrains.
Download dmg file for CodeWhisperer for the command line dmg file from the docs.
Download DMG file and then move the file to Applications. (typical drag and drop for MacOS applications)
After installation, start the newly installed CodeWhisperer application
- Install the shell integration hooks as the next step in the installation.
- As a next step we need to enable accessibility so that CodeWhisperer can write on insert CLI completions and insert commands in the shell. CodeWhisperer will not work if this is not enabled.
- Toggle the accessibility for CodeWhisperer.
- Next step will ask to sign on. Upon clicking you will redirected to authorise CodeWhisperer for your AWS account.
- You will need an AWS Builder ID. If you already have a Builder ID use your existing credentials otherwise create once as shown in image below. In my case I already have a Builder ID
As a last step, if you have setup everything correctly so far, you will see a prompt in which you allow COdewhisperer to access your data so that CodeWhisperer can do the following:
- Enable CodeWhisperer completions
- Enable CodeWhisperer analysis
- Access to IAM Identity centre accounts and permission sets.
- Once the setup is complete, you will see the code whisperer default window.
With CodeWhisperer you can write natural language ( many languages are supported) instructions like
create s3 bucketor
create a lambda function. Codewhisperer will then convert this text to an instantly executable shell command.
You can either use this feature in 2 ways:
cw ai CodeWhisperer completions # CodeWhisperer completions // # is not the comment
- I tried to create cloudfront distribution whose origin is s3 bucket using the following prompt
cw ai create cloudfront distribution named test whose origin is s3 bucket name test -bucket
Once you have found your command you either execute it, or choose to edit it or regenerate, ask another question or cancel it.
You can write the prompt using
# your prompt. In the following I tried to create a lambda in tokyo region and it did pretty good job.
# create cloudfront distribution named test whose origin is s3 bucket name test -bucket
- It also does a great job when it comes to CLI completion in the way it adds *typeahead code completions *
- Not only AWS CLI commands, code whisperer has support for docker, kubectl （tested, git commands too.
You can always customise the behaviour of Codewhisperer from its dashboard which allows to change its theme, disable code whisperer for certain commands, instant execution of dangerous commands like bucket delete etc.
As a DevOps engineer who has to run certain repeated commands every day for daily tasks, I think this update will definitely increase my productivity and make my life way easier with its code completion and text-to-command feature.
As I said before it's in the preview stage, and cannot be used for production but it's going to get even better from this stage.