logo
Menu

Introducing Amazon Q for Java developers on AWS

In this article I'll introduce Amazon Q for Java developers on AWS which use IntelliJ IDEA as IDE.

Published Jan 24, 2024
Last Modified Feb 17, 2024

Introduction

During the last re:Invent AWS introduced Amazon Q in preview, a new generative artificial intelligence- (AI)-powered assistant designed for work that can be tailored to our business. We can use Amazon Q to have conversations, solve problems, generate content, gain insights, and take action by connecting to our company’s information repositories, code, data, and enterprise systems. Amazon Q provides immediate, relevant information and advice to employees to streamline tasks, accelerate decision-making and problem-solving, and help spark creativity and innovation at work.
Amazon Q has several areas of expertise:
  • Your business
  • AWS development
  • Amazon Quicksight
  • Amazon Connect
  • AWS Supply Chain
In this article I'll focus on the AWS development from the point of view of the Java developer using IDE. I'll use IntelliJ IDEA, but Amazon Q is available as an extension in Visual Studio Code as well. To use Amazon Q we first need AWS Toolkit plugin to be installed or updated to the newest version.
AWS_Toolkit_Plugin_Installed
Amazon Q in the IDE provides the following capabilities :
  • Conversational assistant in IDE via CodeWhisperer
  • Code transformation in IDE
  • Feature Development in IDE (code generation coming soon)
To use Amazon Q for the capability 2 and 3 we're required to use Amazon CodeWhisperer Professional Tier , which means we can't use our AWS Builder ID (which works for the 1st capability), but it requires to sign in using the AWS IAM Identity Center credentials provided by our AWS Organization. To access Amazon Q Code, the CodeWhisperer administrator needs to explicitly give access to Amazon Q features in the profile used by the organization.
After being succesfully logged in as described above we can see Amazon Q ready to be used as a part of the AWS Toolkit
Amazon Q in AWS Toolkit
Amazon Q provides more capabilities which are beyond the scope of this article like :
  • Conversational assistant in AWS Management Console , AWS website, AWS documentation, and AWS Chatbot
  • Troubleshooting in AWS console for different services like AWS Lambda
  • Pull request summaries in Amazon CodeCatalyst
  • Feature development in Amazon CodeCatalyst

Capabilities of Amazon Q in the IDE

I'll use my sample Serverless project which consists of API Gateway in front of several Lambda functions and uses DynamoDB as NoSQL datastore. Lambda functions provide logic to save and retrieve products to and from the database. The project uses AWS SDK for Java.
First of all all I'll use "Chat with Q" capability and ask some general questions about the project as a whole :
Amazon_Q_Question_About_General_Architecture
Ok, it looks good. Now let's ask the question about specific Java class :
Amazon_Q_What_Does_This_Code_Do
 Ok, this was very precise as well. As you might know I write blog series about AWS SnapStart. Let's ask about its meaning in the SAM template.
Amazon_Q_Question_About_SnapStart
Not a very precise answer to be honest. Even by answering my general question about the architecture Q provided this information "The SnapStart property indicates it uses SnapStart for faster cold starts.", which answers my previous question better.
Let's ask Amazon Q to suggest the documentation of the handleRequest method:
Amazon_Q_Generate_Documentation
This also looks good. Now let's ask Amazon Q to generate the Junit test for this method :
Amazon_Q_Junit_1a
Amazon_Q_Junit_2
Generally the right idea to mock the database communication with Mockito but not the ideal code which won't even compile (like Product creation). Import statements are missing as well. Here we'll need to do some code adjustements to make it work.
Now let's ask Q as a part of our feature request what we should do in our code to use Lambda Function URL instead of API Gateway :
Amazon_Q_Function_URL
It's one of the options to implement it. Let's ask about the corresponding changes in the SAM template for it:
Amazon_Q_Function_URL_SAM
Ok, this is also one of the options to make it work, another one will be using the following:
Let's ask Q about this option as well:
Amazon_Q_Function_URL_SAM_Another_Option

Ok, Amazon Q understood the context and provided a valid code suggestion.
Currently Amazon Q has very limited possibilities to generate, suggest and insert the code and AWS services configuration itself, like in our cases the relevant Java code, infrastructure-as-a-code (CloudFormation, SAM or CDK) and configuration and dependency management (in Maven or Gradle) in my project in the all relevant places. According to the information provided by the Clare Liguori in the talk Amazon Q: Your new assistant and expert guide for building with AWS this functionallity called "code generation in IDE" is currently under development (but already available in Amazon CodeCatalyst) will require CodeWhisperer Professional Tier as well and will be provided by starting the chat with Q with /dev. This will improve Q service a lot by giving the developers powerful generative AI promt engineering capabilities.
Amazon Q additionally provides the capability to transform the code of Java 8 or 11 project to Java 17. You can use it either via /transform in the Q chat or by using it directly from Amazon Q menu:
Amazon_Q_Transform
The following article Upgrade your Java applications with Amazon Q Code Transformation provides the detailed information about this feature in preview. I found its capabilities currently as very limited, as only code transformation to Java 17 is covered and not to the current LTS version Java 21. The article above says that in addition to generative AI-powered code transformations built by AWS, Amazon Q Code Transformation uses parts of OpenRewrite to further accelerate Java upgrades for customers. It will be interesting to see the additionall benefits of using Amzon Q Code Transformation over using OpenRewrite (which is open source) directly. OpenWrite provides many code refactorings in form of recipes iself. I will be very much interested to see the code transformation possibilities of Lambda with Java runtime with using different frameworks like Spring (Boot), Quarkus and Micronaut, as in many cases it's not only about the upgrade of Java runtime version but also about the version of the framework (and its dependencies) in use. Another use case will be to provide the migration between AWS SDK for Java versions, as I expect the version 3 to be released someday which might not be backwards compatible.

Conclusion

In this article I have provided an overview of Amazon Q from the point of view of the Java developer on AWS which comes as companion of Amazon CodeWhisperer. We saw that we can ask Q specific questions about the code (snippets), ask for improvements or to generate documentation or tests or even give us suggestions for the feature development.
I see a lot of area of improvements for this service (Q is currently in preview) but also potential for programmers. Especially the acceleration of the software development on AWS via the conversational programming with Q (like suggestion the optimal tech stack/service which matches the described requirements) and integration into other AWS services like Amazon CodeGuru and Amazon Inspector.
During the preview period, many of the Amazon Q capabilities are available without any charge. So give it a try! This page contains the information about the pricing when Amazon Q reaches the GA status.
 

1 Comment