AWS Logo
Menu
Fast, agentic coding experience with Amazon Q Developer CLI

Fast, agentic coding experience with Amazon Q Developer CLI

Experience how Amazon Q CLI agent transforms Python scripts to Lambda functions and API Gateway, all from your terminal, dramatically reducing development time.

Nitin Eusebius
Amazon Employee
Published Mar 8, 2025

Introduction

As developers , we're constantly looking for ways to streamline our workflows and increase productivity. The recently announced Amazon Q Developer enhanced CLI agent represents a significant leap forward in how we interact with our development environments. Unlike traditional AI assistants that simply provide suggestions, this enhanced CLI agent actively works alongside you, executing commands, generating code, and deploying infrastructure with minimal intervention.
You can now ask Q Developer to write code, test it, help debug issues, and Q Developer will iteratively make adjustments based on your feedback and approval. This allows you to efficiently complete tasks, improving and streamlining the development process, without needing to leave your terminal.
The enhanced CLI agent, powered by Anthropic's most intelligent model to date, Claude 3.7 Sonnet, is available on Amazon Q Developer Free, and Pro tiers and in all AWS regions where Q Developer is available. Learn more.
In this article, I'll demonstrate how the Amazon Q Developer enhanced CLI agent transforms a standard Python script into a fully deployed AWS Lambda function with API Gateway integration using SAM, all without leaving your terminal. You'll see how this new capability dramatically reduces development time and cognitive overhead, allowing you to focus on solving business problems rather than dealing with implementation details.

The Challenge: From Scripts to Serverless

Many developers start with a simple script that works locally and then need to transform it into a production-ready serverless function. This process typically involves:
  1. Refactoring the code to work within a Lambda handler
  2. Creating appropriate IAM permissions
  3. Setting up API Gateway endpoints
  4. Configuring deployment parameters with SAM or CloudFormation
  5. Testing and troubleshooting deployment issues
Each of these steps requires context switching between documentation, various services, and different tools. The Amazon Q Developer CLI agent simplifies this process by handling these tasks in a conversational interface directly in your terminal.

Our Starting Point: A Simple Bedrock API Script

Let's start with a basic Python script that uses AWS Bedrock to interact with Amazon Bedrock Model
This script works fine for local testing, but deploying it as a serverless function requires some refactoring and configuration.

Enter Amazon Q Developer CLI Agent

With the enhanced Q Developer CLI agent, we can transform this script into a deployed Lambda function accessed via Amazon API Gateway through a simple conversation. Let's see this in action.

Step 1: Starting the Conversation

First, I launch the Amazon Q CLI and explain what I want to accomplish:

Step 2: Project Setup and Code Transformation

Without any additional prompting, the Amazon Q CLI agent:
  1. Create a SAM template file
  2. Create a Lambda function handler
  3. Create a requirements.txt file
  4. Create a README.md with deployment instructions

Creating a SAM template file

The agent continues to create the SAM template file for deployment

Creating a Lambda function handler

The agent continues to create the lambda function

Creating a requirements.txt file

The agent continues to create requirements.txt with dependancies for deployment

Creating a README.md with deployment instructions

Finally the agent continues to create the README.md file with further instructions
Now if needed, we can end the session (want to demo other aspects of post session end) and deploy the code as shown below using sam build and deploy

Step 3: Testing and Debugging

With everything set up, I simply ask the agent to help test the deployed API. The agent systematically investigates the deployed API by first examining project files to understand the architecture. It then identifies the API endpoint through AWS CLI commands and conducts multiple tests using curl with different queries. Through these tests, the agent discovers a bug: regardless of input, the API returns the same "hello world" response. Using verbose curl commands to analyze the full request-response cycle, the agent diagnoses that the Lambda function isn't properly parsing the input message from the API Gateway event structure, suggesting code fixes to extract the message correctly from event['body'] and implement proper JSON parsing.
The agent actively assists in fixing the identified API issue by first thoroughly examining the original Lambda function code. After diagnosis, it implements a comprehensive solution by rewriting the code with several improvements. These include adding detailed event logging for better debugging visibility, properly parsing the JSON body from API Gateway's event structure, implementing robust error handling for malformed JSON requests, creating a fallback mechanism for missing message parameters, and adding appropriate CORS headers to ensure web compatibility. The agent then initiates the SAM build process to prepare the updated Lambda function for deployment, demonstrating a methodical approach to resolving the integration issues between API Gateway and Lambda that had been causing all requests to return the same default "hello world" response regardless of input
After implementing the changes and deploying the updated Lambda function, the agent conducts thorough testing to verify the fix. Using curl commands with different query parameters, the agent confirms that the API now correctly processes user inputs and returns appropriate, varied responses from Claude AI. The first test asking "What is AWS Lambda?" returns a comprehensive explanation of AWS Lambda's serverless computing features, while the second test requesting a one-sentence definition of Amazon S3 returns exactly that ,confirming the API now properly handles different input messages as intended.
The agent explains the specific improvements made to fix the issue: implementing proper event parsing to extract messages from the API Gateway event structure, adding robust error handling for malformed requests, incorporating logging for easier debugging, and adding CORS headers for web application support. The agent also outlines the logical flow of the updated function, which checks for the message in different possible locations with appropriate fallbacks. Finally, the agent suggests next steps to further enhance the API, including adding authentication, implementing rate limiting, setting up monitoring, and enhancing error handling for production readiness.

The Power of Contextual Understanding

What makes the Amazon Q Developer enhanced CLI agent particularly powerful is its deep contextual understanding of both development workflows and available tools. It doesn't just translate code; it transforms it with an understanding of:
  1. Execution environment: Adding proper request parsing, error handling, and response formatting
  2. Integration: Ensuring the Lambda function works correctly with API Gateway requests
  3. IAM security: Configuring the minimum necessary permissions for Bedrock access
  4. Development best practices: Creating a proper project structure with README, .gitignore, and versioning
  5. Deployment workflows: Automating the SAM build and deployment process

Conclusion: The Future of Developer Experience

The Amazon Q Developer enhanced CLI agent represents a significant evolution in how we interact with development tools. By combining conversational AI with the ability to take concrete actions—executing commands, generating code, and deploying infrastructure, it fundamentally changes what's possible in a terminal environment.
As someone who spends hours each day in the terminal, having an AI assistant that can work alongside me, understanding my intent, executing commands, making file changes, and reasoning through complex problems, has fundamentally changed how I approach development tasks.
If you haven't tried the enhanced Amazon Q Developer enhanced CLI agent yet, I highly recommend giving it a go. The initial setup takes just a few minutes, and the productivity gains are immediate and substantial. The future of developer experience is here, and it's more collaborative and intelligent than we could have imagined.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments