This lesson on Deployment — Docker, Gunicorn/Uvicorn, Cloud is hands-on and example-driven. You will leverage Amazon Q Developer CLI (QCLI) to diagnose local FastAPI application state, automate multi-file code refactoring using natural language prompts, and provision AWS EC2 infrastructure for cloud deployment. This workflow eliminates manual infrastructure scripting by integrating contextual system awareness and direct command execution.
What You'll Be Able To Do
- Navigate system directories and execute development commands using QCLI context-aware autocomplete.
- Inspect local FastAPI runtime behavior and diagnose functional defects using Uvicorn with auto-reload.
- Refactor backend logic, CSS styling, and frontend templates simultaneously using natural language prompts in QCLI.
- Evaluate execution permissions and security risks before allowing AI agents to read, write, or execute shell commands.
- Deploy a full-stack FastAPI application to an AWS EC2 instance using automated natural language provisioning commands.
Detailed Concept Walkthrough
1. Amazon Q Developer CLI Architecture
QCLI is a terminal-native AI development assistant that interfaces directly with local operating system contexts and AWS services. It bridges natural language intent with programmatic shell and file-system execution.
- Context Integration: QCLI inspects the developer's working directory, environment variables, and underlying operating system state to ground LLM reasoning in the immediate project context.
- Under the Hood: The CLI layer interfaces with foundational models (such as Claude via AWS) to translate plain language requests into concrete AWS CLI commands, shell invocations, and file edits.
- Execution Trust: Because QCLI holds permissions to execute arbitrary bash scripts and mutate source files, developers must review and approve proposed commands to prevent unintended system side effects.
# Open the interactive Amazon Q Developer CLI chat
q chat
# Query context awareness and system capabilities
> What AWS resources and local files can you access in this directory?
Key Takeaway: QCLI pairs local environment context with AWS service integration to execute operational tasks from natural language prompts.
2. Context-Aware Autocomplete and CLI Assistance
QCLI enhances standard terminal shells by overlaying inline documentation and predictive command completions for standard toolchains like Git, Docker, and AWS CLI.
- Mechanism: As a developer types common development commands (e.g.,
docker,git,cd), QCLI intercepts input to suggest relevant subcommands, flags, and contextual parameter values. - Under the Hood: Autocomplete relies on static command schemas merged with local environment metadata, such as active branches, local container images, and directory paths.
- Best Practice: Use inline autocomplete suggestions to avoid syntax errors and verify parameter flags without interrupting development to consult external documentation.
# QCLI provides dynamic suggestions and flag definitions during typing
cd ./budget_app/
docker build -t fastapi-app:latest .
git status
Key Takeaway: Intelligent command-line autocomplete reduces context switching by embedding tool documentation directly into active terminal sessions.
3. Local Application Diagnosis with Uvicorn
Verifying FastAPI backend logic and frontend responses locally ensures defects are identified before initiating cloud provisioning.
- Execution Flow: The developer activates the project's Python virtual environment and launches the ASGI server using Uvicorn with the reload flag enabled for dynamic hot-reloading.
- State Inspection: Navigating to the local host port reveals the rendered application state and highlights missing business rules, such as unhandled budgeting constraints.
- Under the Hood: Uvicorn monitors filesystem changes on the application entry point module and reloads worker processes upon detecting code modifications.
# Activate the virtual environment
source .venv/bin/activate
# Start the FastAPI ASGI server with auto-reload enabled
uvicorn main:app --reload --host 127.0.0.1 --port 8000
Key Takeaway: Local ASGI execution validates runtime behavior and pinpoints defects prior to automated cloud deployment.
4. AI-Assisted Multi-File Refactoring
Natural language instructions can coordinate coordinated edits across backend business rules, stylesheets, and frontend presentation layers simultaneously.
- Mechanism: QCLI parses requirements stated in natural language (e.g., enforcing the 50/30/20 budgeting rule) and identifies every dependent file in the repository tree.
- Under the Hood: The assistant generates diffs across Python backend endpoints, CSS stylesheets, and template files to ensure end-to-end consistency for new features.
- Best Practice: Always inspect multi-file diffs generated by the AI to ensure business logic constraints and styling modifications do not overwrite unintended code paths.
# Prompting QCLI chat to perform synchronized full-stack refactoring
> Enforce the 50/30/20 budgeting rule in the backend calculation logic.
> Update the frontend CSS to highlight budgeting rule violations with a red background.
Key Takeaway: QCLI coordinates synchronized updates across backend logic, templates, and styling from a single high-level prompt.
5. One-Step Automated EC2 Deployment
High-level natural language prompts can trigger full infrastructure provisioning and application deployment to AWS compute resources.
- Mechanism: Passing deployment instructions into QCLI initiates an automated synthesis of required AWS infrastructure configurations and installation scripts.
- Execution Flow: QCLI provisions an EC2 instance, configures networking and security groups, transfers application artifacts, and bootstraps the FastAPI runtime service.
- Nuance: Automated provisioning abstracts manual AWS Console and CloudFormation scripting, requiring the operator to confirm resource creation parameters to manage cloud costs.
# Execute one-step infrastructure provisioning and deployment via QCLI
> deploy this entire app to an EC2
Key Takeaway: Natural language deployment commands allow AI agents to synthesize scripts and provision live cloud compute environments automatically.
Topics Covered in Deployment — Docker, Gunicorn/Uvicorn, Cloud
- Introduction to QCLI (0:00 - 1:20) — The tutorial introduces Amazon Q Developer CLI for full-stack application deployment and resource provisioning on AWS.
- QCLI Autocomplete (1:21 - 2:05) — Intelligent, context-aware command line autocomplete demonstrates suggestions and documentation for tools like Git and Docker.
- QCLI Chatbot Functionality (2:05 - 3:04) — The interactive chatbot demonstrates local system awareness, file execution permissions, and AWS integration capabilities.
- Local Application Diagnosis (3:04 - 4:11) — The FastAPI application runs locally on Uvicorn to identify existing budgeting rule defects in the web interface.
- AI Code Refactoring (4:11 - 5:37) — Natural language prompts instruct QCLI to implement the 50/30/20 budgeting rule and add red visual violation styling.
- One-Step Cloud Deployment (6:37 - 7:17) — A single natural language prompt triggers QCLI to provision an AWS EC2 instance and deploy the application.
FastAPI Cheat Sheet
-
q chat— Opens the interactive Amazon Q Developer CLI chatbot sessionq chat -
uvicorn main:app --reload— Starts local FastAPI ASGI server with live reloadinguvicorn main:app --reload -
source .venv/bin/activate— Activates the local Python virtual environmentsource .venv/bin/activate -
q <natural-language-prompt>— Executes context-aware AI operations or queries directly from the CLIq "explain git status" -
deploy this entire app to an EC2— Triggers automated AWS EC2 provisioning and code deploymentq chat > deploy this entire app to an EC2
Comparison Table
| Deployment Stage | Manual Approach | QCLI AI-Assisted Approach |
|---|---|---|
| CLI Command Entry | Manual flag lookup and manual typing | Context-aware autocomplete with inline documentation |
| Code Refactoring | Manual multi-file edits across backend/frontend | Natural language multi-file diff generation |
| AWS Cloud Deployment | Manual EC2 provisioning and bash scripting | One-step natural language deployment prompt |
Common Pitfalls
- Mistake: Granting unconditional execution trust to AI-generated commands. Avoid: Reviewing all proposed bash commands and file modifications before confirming execution.
- Mistake: Deploying to cloud infrastructure before verifying application behavior locally. Avoid: Running Uvicorn locally to confirm bug fixes and rule enforcement prior to EC2 provisioning.
- Mistake: Attempting cloud deployment without configuring appropriate AWS CLI credentials. Avoid: Ensuring the local terminal has valid AWS permissions before issuing deployment instructions.
FAQs
- How does QCLI maintain awareness of the current application context? QCLI inspects the active working directory, file hierarchy, and operating system state to ground LLM prompts in local project context.
- Why is local Uvicorn testing necessary if QCLI writes the code? Local verification with Uvicorn confirms that backend calculation updates and frontend visual changes function correctly prior to cloud deployment.
- What underlying model powers Amazon Q Developer CLI operations? QCLI integrates native AWS tooling with foundational large language models (such as Claude) to reason over code and infrastructure.
- What happens when you prompt QCLI to deploy to EC2? QCLI interprets the prompt, synthesizes provisioning scripts, initiates an AWS EC2 instance, and deploys the application runtime automatically.