Build modern serverless solutions following best practices using Amazon Q Developer CLI and MCP

This post explores how the AWS Serverless MCP server accelerates development throughout the serverless lifecycle, from making architectural decisions with tools like get_iac_guidance and get_lambda_guidance, to streamlining development with get_serverless_templates, sam_init, to deployment with SAM integration, webapp_deployment_help, and configure_domain. We show how this conversational AI approach transforms the entire process, from architecture design through operations, dramatically accelerating AWS serverless projects while adhering to architectural principles.

Jul 28, 2025 - 19:00
Build modern serverless solutions following best practices using Amazon Q Developer CLI and MCP

Building modern serverless applications on AWS requires navigating best practices to manage the integration between multiple services, such as AWS LambdaAmazon API GatewayAmazon DynamoDB, and Amazon EventBridge. Security considerations, performance optimization, and implementing a comprehensive monitoring systems adds further requirements to build a serverless architecture while adhering to AWS best practices.

Amazon Q Developer CLI with Model Context Protocol (MCP) supports getting started with serverless applications using natural language conversations that produce infrastructure configurations and architectural guidance aligned with AWS best practices. This reduces the need to manually research documentation or piece together solutions from disparate sources.

This post explores how the AWS Serverless MCP server accelerates development throughout the serverless lifecycle, from making architectural decisions with tools like get_iac_guidance and get_lambda_guidance, to streamlining development with get_serverless_templates, sam_init, to deployment with SAM integration, webapp_deployment_help, and configure_domain. We show how this conversational AI approach transforms the entire process, from architecture design through operations, dramatically accelerating AWS serverless projects while adhering to architectural principles.

Solution overview

Amazon Q Developer CLI serves as a powerful terminal-based gateway to the AI capabilities of Amazon Q, bringing conversational intelligence directly to your command line environment. Although you can also apply this approach to conversational AI in the interactive development environment’s (IDE’s) agentic chat, this innovative interface transforms how developers work by enabling natural language interactions with AWS services and development tools without leaving the terminal. By typing queries or requests in plain English, developers can harness the full potential of generative AI with Amazon Q to solve complex problems, generate code snippets, troubleshoot issues, and access AWS best practices—all from the familiar comfort of their preferred terminal application.

However, although Amazon Q CLI provides the conversational interface, it needs a way to connect with external tools and data sources. This is where MCP comes in.

MCP is a groundbreaking open standard created by Anthropic that bridges the gap between AI models and external data sources or tools. This protocol establishes a unified framework allowing large language models (LLMs) to seamlessly interact with diverse information systems and specialized capabilities. When applied to serverless development workflows, this capability transforms how developers build AWS applications.

MCP transforms Amazon Q CLI for serverless development by bridging the gap between traditional approaches and modern AI-assisted workflows. This integration replaces manual documentation research and trial-and-error development with conversational access to AWS expertise, automated code generation, and intelligent configuration assistance—directly from the command line.

Now that we have discussed the conceptual benefits of Amazon Q CLI and MCP, let’s explore how to set up these tools in your development environment.

Prerequisites

You must have the following prerequisites:

Prepare your environment

Before you can start constructing this serverless solution, you must configure your IDE by installing and setting up Amazon Q CLI and the AWS Serverless MCP server. This section provides comprehensive guidance for properly installing and configuring the required components.

Install Amazon Q Developer CLI You can install Amazon Q Developer CLI independently on your system. To get started, complete the following steps:

  1. Confirm successful installation with this terminal command:
q --version 

The system should now show something similar to the following output:

q 1.x.x
  1. Log in to your AWS account:
q login
  1. Select your preferred authentication option:

Set up MCP servers

Before you can start using MCP servers with Amazon Q CLI, you must install several prerequisites and configure your environment. Complete the following steps:

Install uv with the following command:

pip install uv

Install Python 3.10 or newer using the following command:

uv python install 3.10

Add the following code to your MCP client global configuration (~/.aws/amazonq/mcp.json file). This can be configured by project (.amazonq/mcp.json) in the current folder. The AWS Serverless MCP server uses the default AWS profile by default. Specify a value in AWS_PROFILE if you want to use a different profile. Similarly, adjust the AWS Region and log-level values as needed:

{
    "mcpServers": {
        "awslabs.aws-serverless-mcp": {
            "command": "uvx",
            "args": [
                "awslabs.aws-serverless-mcp-server"
            ],
            "env": {
                "AWS_PROFILE": "your-aws-profile",
                "AWS_REGION": "us-east-1",
                "FASTMCP_LOG_LEVEL": "ERROR"
            }
        }
    }
}

Amazon Q CLI seamlessly detects and integrates with MCP servers configured in the ~/.aws/amazonq/mcp.json file.

The MCP servers support several configuration options to customize your development experience:

  • Auto-approve – Configure which tools can be used without prompting for approval
  • Environment variables – Customize server behavior through environment variables
  • Disabled flag – Temporarily disable specific servers when not needed

The following is an example of how to configure your AWS Serverless MCP server using the preceding options:

{
    "mcpServers": {
        "awslabs.aws-serverless-mcp": {
            "command": "uvx",
            "args": [
                "awslabs.aws-serverless-mcp-server"
            ],
            "env": {
                "AWS_PROFILE": "your-aws-profile",
                "AWS_REGION": "us-east-1",
                "FASTMCP_LOG_LEVEL": "ERROR"
            },
            "disabled": false,
            "autoApprove": [
                "search_documentation",
                "read_documentation",
                "recommend"
            ],
            "trusted": [
                "search_documentation",
                "read_documentation",
                "recommend"
            ]
        }
    }
}

Test your setup

To verify that everything is working correctly, generate a simple serverless function. Start the Amazon Q CLI chat interface and verify the output shows MCP servers being loaded and initialized:

q chat

The message in the preceding screenshot might not match what you see for your use case, especially when your MCP servers take longer to load.

Now that you’ve confirmed your environment is properly configured, you can begin exploring the serverless development workflow. The first step in this journey is making informed architectural decisions that will shape your application.

Architecture and design phase

The architecture and design phase is where your serverless application takes shape. Making the right decisions at this stage can significantly impact your project’s success, scalability, and maintainability. The AWS Serverless MCP server provides powerful tools to guide these critical early decisions.

When starting a new serverless project, choosing the right infrastructure as code (IaC) approach is crucial for long-term success. The AWS Serverless MCP server’s get_iac_guidance_tool transforms this decision-making process from hours of research into a simple conversation. This powerful tool provides comprehensive, contextual guidance tailored to your specific needs by analyzing factors such as:

  • Project complexity and scale
  • Team expertise and preferences
  • Required deployment flexibility
  • Local testing requirements
  • Long-term maintenance considerations

Let’s see how this works in practice by asking Amazon Q about the best IaC approach for your serverless application:

What's the best IaC approach for my serverless application?

Because Amazon Q is using get_iac_guidance for the first time, it will ask you to enter t to trust this tool for the entire session, y to allow the execution of this tool only one time, or n to reject the execution of this tool.

The following example is for an ecommerce application.

After approving the tool usage, you will receive a comprehensive, contextual response tailored to your specific architecture needs. For example:

AWS SAM for Your E-Commerce Microservices

Based on your e-commerce microservices architecture, I recommend AWS SAM (Serverless Application Model) as your primary IaC tool for the serverless components of your application. 

Here is why it is particularly well-suited for your needs:

1. Perfect for Your Serverless Components: SAM is specifically designed for the serverless parts of your architecture like the Payment Service (Lambda) and notification systems.

2. Simplified Syntax: SAM provides a simplified way to define Lambda functions, API Gateway, and DynamoDB tables - all key components in your architecture.

3. Local Testing: You can test your Lambda functions locally before deployment, which is crucial for your payment processing service.

4. Integration with Your Architecture: SAM works seamlessly with the API Gateway and Lambda components shown in your diagram.

5. Deployment Independence: Supports your microservices approach where "each microservice can be deployed independently" as mentioned in your documentation.

Example SAM Template for Your Payment Service:

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  PaymentFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./payment-service/
      Handler: index.handler
      Runtime: nodejs22.x
      Policies:
        - SQSPollerPolicy:
            QueueName: !GetAtt PaymentQueue.QueueName
      Events:
        SQSEvent:
          Type: SQS
          Properties:
            Queue: !GetAtt PaymentQueue.Arn
            BatchSize: 10

  PaymentQueue:
    Type: AWS::SQS::Queue
    Properties:
      VisibilityTimeout: 300

Development acceleration phase

After you’ve made key architectural decisions, you enter the development phase. This is often the most time-consuming part of the process, requiring significant effort to implement patterns correctly, handle edge cases, and follow best practices. The AWS Serverless MCP server provides tools that dramatically accelerate this phase by using proven patterns and templates.

The get_serverless_template tool alleviates the need to start from scratch by providing access to production-ready serverless patterns from the AWS Serverless Land GitHub repository. These patterns are tested, follow AWS best practices, and can be customized to meet your specific requirements.

Let’s say you want to understand more about serverless architecture. With this tool, you can discover and implement common serverless architectures with a simple conversation. For example, you can ask Amazon Q the following question:

Show me Node.js API templates for serverless applications

Because Amazon Q is using get_serverless_templates for the first time, it will ask you to enter t to trust this tool for the session, y to trust the tool only for this time, or n to reject the use of this tool.

You will have to trust at least this tool if not more. After trusting the tool, you should get a response similar to the following:

Here are some Node.js API templates for serverless applications on AWS:

1. API Gateway to SQS Integration

This template creates a REST API Gateway that directly integrates with AWS SQS to read messages:

Key Features:
- Direct service integration between API Gateway and SQS
- No Lambda function required
- Support for query string parameters
- Ideal for retrieving messages via HTTPS without AWS SDK

Use Cases:
- Web applications polling SQS queues
- Mobile apps requiring secure access to SQS
- Third-party integrations

GitHub Link: https://github.com/aws-samples/serverless-patterns/tree/main/APIGateway-SQS-ReceiveMessages

2. Application Load Balancer with Lambda REST API

While this example uses Python, the pattern is applicable to Node.js as well:

Key Features:
- Path-based listener rules on ALB
- Lambda function as the target
- RESTful API implementation

GitHub Link: https://github.com/aws-samples/serverless-patterns/tree/main/alb-lambda-rest-api-sam-py

3. Full-Stack Integration: Amplify + Cognito + API Gateway + Lambda

This template demonstrates a complete serverless stack with authentication:

Key Features:
- AWS Amplify frontend
- Cognito for authentication
- API Gateway with Cognito authorizer
- Lambda backend
- Environment variables shared between frontend and backend

GitHub Link: https://github.com/aws-samples/serverless-patterns/tree/main/amplify_cognito_apigateway_lambda_envvariables

Development and testing phase

The development and testing phase is where your serverless application takes shape through code. This phase requires tools that streamline the creation, building, and testing of your application components. The AWS Serverless MCP server provides a suite of tools that integrate seamlessly with the AWS SAM CLI, enabling a smooth development experience from project initialization to local testing.

Beginning a new serverless project with the right structure and configuration can be challenging. The sam_init tool reduces this hurdle by creating well-structured projects that follow AWS best practices out of the box. This tool provides templates for various serverless application types, helping you start with a solid foundation.

For example, you can ask the following question:

Create a new SAM project for a Python REST API

Because Amazon Q is using sam_init for the first time, it will ask you to enter t to trust this tool for the session, y to trust the tool only for this time, or n to reject the use of this tool.

The sam_init tool is used to initialize a new serverless application using AWS SAM. It creates a complete project structure with the necessary files to develop, test, and deploy serverless applications on AWS.

The tool has the following key capabilities:

  • It creates a new project directory with a standardized structure for serverless applications
  • It generates an AWS SAM template file (template.yaml) that defines your infrastructure as code
  • It sets up the initial code for Lambda functions in your chosen runtime (Python, Node.js, and so on)
  • It configures the project with the appropriate dependency management system

For your ecommerce microservices architecture, this tool would be particularly useful for:

  • Creating individual microservices (like your product catalog service or payment service)
  • Setting up serverless API endpoints through API Gateway
  • Establishing the foundation for event-driven communication between services

The tool supports various application templates and runtimes, helping you quickly bootstrap different types of serverless applications, from simple APIs to more complex event-processing systems.

Deployment and configuration phase

After you have developed and tested your serverless application locally, the next step is deploying it to the AWS Cloud. This phase often involves complex, multi-step processes to make sure the components are properly deployed, configured, and integrated. The AWS Serverless MCP server provides specialized tools that simplify these processes, enabling smooth deployments with minimal manual intervention.

Streamline full-stack deployments

For this use case, we’re building a full-stack serverless application with a React frontend, Node.js backend APIs, and DynamoDB database. Traditionally, this would require manually configuring multiple AWS services, managing deployment pipelines, and validating proper integration between components.

The webapp_deployment_help tool transforms this complex process into a single, streamlined operation that handles the different aspects of deployment while following AWS best practices.

You can ask Amazon Q the following question:

Deploy my React application to AWS with serverless backend

Because Amazon Q is using webapp_deployment_help for the first time, it will ask you to enter t to trust this tool for the session, y to trust the tool only for this time, or n to reject the use of this tool. For this example, trust this tool for the session.

This tool supports three deployment types:

  • Backend only – Deploys a backend application to Lambda with API Gateway
  • Frontend only – Deploys a frontend application to Amazon Simple Storage Service (Amazon S3) and Amazon CloudFront
  • Full stack – Deploys both backend and frontend components together

It uses AWS Lambda Web Adapter, so you can deploy standard web applications (like Express.js, Flask, and React) to Lambda without needing to modify your code to follow Lambda-specific conventions.

For your ecommerce microservices architecture, this tool is particularly useful because it aligns with several components in your diagram:

  • It can deploy your frontend to CloudFront
  • It can deploy your microservices as Lambda functions or containers
  • It integrates with API Gateway for API management

The tool requires you to build your application first using your framework’s build command (like npm run build for React), then it handles the deployment to AWS, including setting up the necessary infrastructure.

Set up custom domains

Although your application is now deployed and accessible using AWS generated URLs, professional applications typically require branded, custom domain names for a better user experience. However, configuring custom domains traditionally involves multiple complex steps across several AWS services. The configure_domain tool simplifies this process into a single, intuitive conversation.

You can ask Amazon Q the following question:

Configure my custom domain example.com for my serverless application

Because Amazon Q is using configure_domain for the first time, it will ask you to enter t to trust this tool for the session, y to trust the tool only for this time, or n to reject the use of this tool.

Get the steps to configure your domain as follows:

Steps to Configure a Custom Domain for Your Serverless Application

1. Prerequisites 
- Ensure you own the domain name (example.com) 
- Have a Route 53 hosted zone for your domain 
- Have deployed your serverless application (e.g., your e-commerce-app)

2. Create an SSL Certificate with AWS Certificate Manager (ACM)
- bash
# Request a certificate for your domain. Region must be us-east-1 for CloudFront distributions
- aws acm request-certificate --domain-name example.com --validation-method DNS --region us-east-1
# Note the certificate ARN from the output

3. Validate the Certificate 
- Go to the ACM console 
- Find your certificate and click on it 
- Create the DNS validation records in Route 53 
- Wait for validation to complete (can take up to 30 minutes)

The tool orchestrates a comprehensive domain setup process that includes the following steps:

  • Creating and validating AWS Certificate Manager (ACM) certificates for secure HTTPS connections
  • Configuring Amazon Route 53 DNS records to point to your application
  • Setting up API Gateway custom domain mappings
  • Associating CloudFront distributions with your domain
  • Establishing proper cache behaviors and security settings

This automation alleviates the need to navigate between multiple AWS console pages and services, reducing the risk of configuration errors while making sure your domain setup follows security best practices. The tool also handles the complexities of certificate validation and DNS propagation, providing clear guidance throughout the process.

With configure_domain, you can transform your application’s user experience from generic AWS endpoints to professional, branded domains in minutes rather than hours.

Having walked through the complete serverless development lifecycle—from architecture decisions to deployment and configuration—we can now appreciate the transformative impact of Amazon Q CLI with MCP on the entire process.

Next steps

To continue your serverless journey with Amazon Q CLI and MCP, we recommend a progressive approach to building your expertise:

  • Begin with a simple project like a basic Lambda function triggered by an API Gateway endpoint or Amazon S3 event to familiarize yourself with the conversational development workflow and gain confidence in the generated solutions.
  • Explore different serverless patterns by experimenting with event-driven architectures using EventBridge for decoupled communication, orchestration workflows with AWS Step Functions, or building comprehensive API-backed applications with API Gateway and Lambda.\
  • As your applications mature, integrate the generated code into your continuous integration and deployment pipelines using services like AWS CodePipeline or AWS CodeBuild to automate testing and deployment processes.
  • Enhance your applications with robust observability by implementing monitoring, logging, and tracing using Amazon CloudWatch, AWS X-Ray, and Powertools for AWS Lambda (Python) to gain insights into performance and troubleshoot issues effectively.
  • Share your experiences and suggestions with the community to contribute to the improvement of MCP servers and help shape the future of AI-assisted serverless development.

Conclusion

By using Amazon Q CLI with MCP servers, you can accelerate your serverless application development while adhering to AWS best practices. This approach helps you focus on your business logic while Amazon Q handles the implementation details, resulting in more robust, scalable, and secure applications.

The ability to generate code, configurations, and architecture recommendations in minutes rather than hours creates a comprehensive development experience that makes sure the different components adhere to best practices while providing actionable, specific implementation guidance. The iterative nature of this approach helps teams quickly compare different architectural decisions through simple prompts, while continuously validating their implementations against official AWS documentation.

Having explored the capabilities and benefits of this approach, you’re now ready to apply these concepts in your own projects.

As you continue exploring serverless application development with Amazon Q CLI and MCP, we encourage you to deepen your knowledge with the following resources:

  • The MCP documentation provides valuable insights into how MCP enhances the capabilities of Amazon Q beyond basic interactions.
  • The AWS SAM documentation offers comprehensive guidance for serverless application development patterns and deployment strategies.
  • To learn more about Amazon Q CLI, refer to Using Amazon Q Developer on the command line.
  • When focusing on architectural excellence, the AWS Well-Architected Framework provides foundational principles for implementing security, reliability, performance efficiency, cost optimization, and operational excellence.
  • For serverless-specific architectural guidance that addresses the unique characteristics of this computing model, refer to the specialized Serverless Lens for Well-Architected Framework tailored specifically for serverless applications.
  • To enhance your development workflow, Powertools for AWS Lambda (Python) offers ready-to-use utilities for structured logging, metrics collection, and distributed tracing. Additionally, the AWS MCP servers documentation offers domain-specific assistance tailored to your project requirements.
  • The serverless community provides valuable resources through AWS Serverless Land, a curated collection of serverless resources, patterns, and examples, and Serverless Stack, an open source framework for building production-ready serverless applications with integrated best practices.

Start building your next serverless application with Amazon Q CLI and MCP today.


About the authors

Dunieski Otano is a Solutions Architect at Amazon Web Services based out of Miami, Florida. He works with World Wide Public Sector MNO (Multi-International Organizations) customers. His passion is Security, Machine Learning and Artificial Intelligence, and Serverless. He works with his customers to help them build and deploy high available, scalable, and secure solutions. Dunieski holds 14 AWS certifications and is an AWS Golden Jacket recipient. In his free time, you will find him spending time with his family and dog, watching a great movie, coding, or flying his drone.

Varun Jasti is a Solutions Architect at Amazon Web Services, working with AWS Partners to design and scale artificial intelligence solutions for public sector use cases to meet compliance standards. With a background in Computer Science, his work covers broad range of ML use cases primarily focusing on LLM training/inferencing and computer vision. In his spare time, he loves playing tennis and swimming.

Joel Asante, an Austin-based Solutions Architect at Amazon Web Services (AWS), works with GovTech (Government Technology) customers. With a strong background in data science and application development, he brings deep technical expertise to creating secure and scalable cloud architectures for his customers. Joel is passionate about data analytics, machine learning, and robotics, leveraging his development experience to design innovative solutions that meet complex government requirements. He holds 13 AWS certifications and enjoys family time, fitness, and cheering for the Kansas City Chiefs and Los Angeles Lakers in his spare time.

Jat AI Stay informed with the latest in artificial intelligence. Jat AI News Portal is your go-to source for AI trends, breakthroughs, and industry analysis. Connect with the community of technologists and business professionals shaping the future.