Welcome to Chapter 14! So far, we’ve explored the foundational concepts of AWS Kiro, learned how to set up our environment, and experimented with basic code generation. Now, it’s time to bring all that knowledge together in a practical, hands-on project. This chapter will guide you through using Kiro to enhance a simple web application, demonstrating its power in a real-world development scenario.
In this project, you’ll learn how to leverage Kiro’s agentic capabilities to add a new feature to an existing Python Flask web application. We’ll focus on defining clear tasks for Kiro, observing its planning and execution, and iteratively refining the generated code. This process will solidify your understanding of Kiro’s workflow and build your confidence in using AI-powered development tools.
Before we dive in, make sure you have successfully completed the setup steps from previous chapters, particularly ensuring your AWS Kiro CLI (kiro-cli) and any preferred IDE integration (like the Kiro extension for VS Code) are fully functional and authenticated with your AWS account. You should also have Python 3.9+ and pip installed. Ready to build something awesome with Kiro? Let’s get started!
Core Concepts: Agent-Driven Application Enhancement
When we talk about “agent-driven application enhancement” with Kiro, we’re referring to a development paradigm where an AI agent (Kiro) actively assists in understanding, planning, coding, and testing new features or modifications to an existing codebase. It’s more than just code completion; it’s about intelligent collaboration.
Understanding the Agentic Workflow
Think of Kiro as a highly skilled, albeit digital, junior developer. You provide it with a high-level task, and it breaks it down, proposes solutions, writes code, and even helps test it. This workflow typically involves:
- Context Assimilation: Kiro first needs to understand the existing project structure, dependencies, and current code logic. This is where Kiro’s ability to index and comprehend your project context comes into play.
- Task Interpretation: You articulate the desired enhancement in natural language. Kiro interprets this request, identifying the core requirements and potential areas of impact.
- Planning and Strategy: Kiro proposes a plan of action. This might include which files to modify, new files to create, dependencies to add, and how to test the new functionality.
- Code Generation & Modification: Based on its plan, Kiro generates or modifies code incrementally, explaining its changes along the way.
- Testing & Validation: Kiro can generate tests for the new code and even help you run them, providing feedback on potential issues.
- Iteration & Refinement: You review Kiro’s output. If something isn’t quite right, you provide feedback, and Kiro iterates to refine the solution.
This iterative process is crucial for complex tasks. It’s rare for an AI to get a perfect solution on the first try, especially with nuanced requirements. Your role is to guide and validate.
Let’s visualize this workflow:
Why Kiro for Application Enhancement?
- Speed: Kiro can rapidly prototype new features or generate boilerplate code, significantly accelerating initial development.
- Consistency: By adhering to best practices and existing code styles (if well-defined in your project context), Kiro can help maintain code quality.
- Learning: Observing Kiro’s process can offer insights into different ways to approach a problem, especially for less familiar technologies.
- Reduced Cognitive Load: Kiro handles the repetitive or complex initial coding, allowing you to focus on architectural decisions and critical business logic.
This project will demonstrate these benefits by having Kiro add a “Quote of the Day” API endpoint to a simple Flask application.
Step-by-Step Implementation: Building a “Quote of the Day” Endpoint
We’ll start with a very basic Flask application and then guide Kiro to add a new API endpoint.
Step 1: Set Up Our Base Flask Application
First, let’s create a minimal Flask application. This will be our starting point.
Create a Project Directory: Open your terminal or command prompt and create a new directory for our project.
mkdir kiro-web-enhancement cd kiro-web-enhancementCreate a Virtual Environment: It’s always good practice to use a virtual environment for Python projects.
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activateInstall Flask: Now, install the Flask web framework.
pip install Flask==2.3.3 # As of 2026-01-24, Flask 2.3.x is stable.Note: We specify a stable version to ensure consistency, though Kiro generally handles dependency resolution well.
Create
app.py: Create a file namedapp.pyin yourkiro-web-enhancementdirectory and add the following basic Flask code:# app.py from flask import Flask, jsonify app = Flask(__name__) @app.route('/') def home(): """ Returns a simple welcome message for the home page. """ return "Welcome to the Kiro-enhanced Web App!" @app.route('/health') def health_check(): """ Returns a simple health check status. """ return jsonify({"status": "healthy"}), 200 if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=5000)Explanation:
from flask import Flask, jsonify: We import the necessary components from Flask.Flaskis the core application object, andjsonifyhelps us return JSON responses.app = Flask(__name__): This creates our Flask application instance.@app.route('/'): This decorator registers thehomefunction to handle requests to the root URL (/).@app.route('/health'): This registershealth_checkfor/health, returning a JSON status.if __name__ == '__main__': app.run(...): This block ensures the development server runs when the script is executed directly.debug=Trueenables automatic reloading and debugging.
Run the Application (Optional, but Recommended): You can test your base application by running:
flask runThen open your browser to
http://127.0.0.1:5000/andhttp://127.0.0.1:5000/health. You should see the welcome message and the health status. PressCtrl+Cto stop the server.
Step 2: Initialize Kiro for the Project
Now, let’s tell Kiro about our new project.
Initialize Kiro: Ensure you are in the
kiro-web-enhancementdirectory and your virtual environment is active. Then, initialize Kiro:kiro-cli initExplanation:
kiro-cli initsets up the necessary Kiro configuration files (e.g.,.kiro/config.yaml) in your project, allowing Kiro to index your codebase and manage agent interactions. It creates a local context for Kiro to operate within.
Verify Kiro Context: Kiro will scan your project. You can usually see its activity in your Kiro IDE extension or by checking the
.kirodirectory.
Step 3: Instruct Kiro to Add the “Quote of the Day” Endpoint
This is where the magic happens! We’ll give Kiro a clear task.
Open Kiro Interface: Open your Kiro-integrated IDE (e.g., VS Code with the Kiro extension). You should see the Kiro chat interface or command palette.
Define the Task: In the Kiro chat or command input, provide the following instruction:
Kiro, I want to add a new API endpoint to this Flask application. The endpoint should be `/api/quote`. When accessed, it should return a random inspirational quote in JSON format. The JSON response should have a key `quote` and a key `author`. For now, use a small hardcoded list of quotes. Please add this endpoint to `app.py`.Explanation:
- We’re being specific: endpoint path, expected JSON structure, and initial data source (hardcoded list). This clarity helps Kiro generate more accurate code.
- We explicitly mention
app.pyto guide Kiro to the correct file.
Observe Kiro’s Planning: Kiro will now process your request. You’ll typically see it “thinking” or “planning” in the interface. It might outline steps like:
- Identify
app.py. - Define a list of quotes.
- Import
randommodule. - Create a new route decorator.
- Implement the logic to select a random quote.
- Return the quote using
jsonify.
- Identify
Review Kiro’s Proposed Changes: Kiro will often present its proposed code changes for your review before applying them. This is a critical step for you to ensure Kiro understood the task correctly and that its approach aligns with your expectations.
Kiro might suggest adding code similar to this to your
app.py:# ... existing imports and app definition ... import random # Kiro might add this import # Hardcoded list of inspirational quotes QUOTES = [ # Kiro might define this list {"quote": "The only way to do great work is to love what you do.", "author": "Steve Jobs"}, {"quote": "Believe you can and you're halfway there.", "author": "Theodore Roosevelt"}, {"quote": "The future belongs to those who believe in the beauty of their dreams.", "author": "Eleanor Roosevelt"} ] # ... existing routes ... @app.route('/api/quote') # Kiro will add this new route def get_random_quote(): """ Returns a random inspirational quote. """ quote = random.choice(QUOTES) # Kiro will add logic to pick a random quote return jsonify(quote) # Kiro will return it as JSONExplanation of Kiro’s likely additions:
import random: Needed for selecting a random item from a list.QUOTES: A list of dictionaries, each containing aquoteandauthor. This matches our requirement for hardcoded quotes.@app.route('/api/quote'): The new route decorator, mapping the URL to the function.get_random_quote(): The function that handles the request.random.choice(QUOTES): Selects one random dictionary (quote) from ourQUOTESlist.jsonify(quote): Converts the selected dictionary into a JSON response.
Accept Kiro’s Changes: If the changes look good, accept them through the Kiro interface. Kiro will then apply these modifications to your
app.pyfile.
Step 4: Test the New Endpoint
Run the Flask Application: In your terminal, activate your virtual environment (if not already) and run:
flask runAccess the New Endpoint: Open your browser or use a tool like
curlto accesshttp://127.0.0.1:5000/api/quote. You should see a JSON response similar to this (the quote will vary):{ "author": "Steve Jobs", "quote": "The only way to do great work is to love what you do." }Refresh the page a few times to confirm that different quotes are returned randomly.
Congratulations! You’ve successfully used Kiro to add a new feature to your web application.
Mini-Challenge: Expanding the Quote List
Now it’s your turn to guide Kiro further!
Challenge:
Instruct Kiro to expand the hardcoded QUOTES list in app.py by adding at least two more inspirational quotes of your choice. Ensure the new quotes also have both a quote and an author key.
Hint:
Use a clear, natural language instruction in the Kiro interface. For example: “Kiro, please add two more quotes to the QUOTES list in app.py. Here are the new quotes: ‘Quote 1’ by ‘Author 1’ and ‘Quote 2’ by ‘Author 2’.”
What to Observe/Learn:
- How well Kiro integrates new data into an existing data structure.
- Whether Kiro correctly parses your natural language input for the new quotes.
- The ease of making minor data-centric updates using Kiro.
- Verify the
app.pyfile to see the updatedQUOTESlist and test the/api/quoteendpoint again to ensure the new quotes appear.
Common Pitfalls & Troubleshooting
Working with AI agents like Kiro is powerful, but it comes with its own set of challenges.
Vague Instructions:
- Pitfall: Providing Kiro with unclear or ambiguous instructions. For example, just saying “add a quote API” without specifying the endpoint, response format, or data source.
- Troubleshooting: Be as specific as possible. Break down complex tasks into smaller, atomic instructions. If Kiro’s initial output isn’t right, rephrase your prompt, adding more detail and constraints. Think about what a human developer would need to know.
Incorrect Context:
- Pitfall: Kiro might make changes to the wrong file or assume incorrect project structure if its context isn’t properly initialized or if you’re working in a complex monorepo.
- Troubleshooting: Ensure
kiro-cli initwas run in the correct root directory. Explicitly mention file paths (e.g., “inservices/user_service.py”) in your prompts. If using an IDE extension, ensure it’s pointing to the correct workspace. Review Kiro’s proposed changes before accepting them. If Kiro asks for clarification, provide it.
Dependency Management Issues:
- Pitfall: Kiro might suggest using a library that isn’t installed or isn’t compatible with your project’s existing dependencies. While Kiro can often suggest
pip installcommands, sometimes manual intervention is needed. - Troubleshooting: Always check
requirements.txtorpyproject.tomlafter Kiro suggests new dependencies. If Kiro adds animportstatement for a new library, Kiro should also suggest adding it to yourrequirements.txtor similar. If not, manually add it and runpip install -r requirements.txt. Keep an eye on version conflicts, especially in older projects.
- Pitfall: Kiro might suggest using a library that isn’t installed or isn’t compatible with your project’s existing dependencies. While Kiro can often suggest
Summary
In this chapter, you’ve taken a significant step from understanding Kiro’s capabilities to actively using it for application enhancement.
Here are the key takeaways:
- You successfully initialized Kiro within a new project directory.
- You created a base Python Flask web application.
- You learned to articulate clear, specific tasks for Kiro agents.
- You observed Kiro’s planning process and reviewed its proposed code changes.
- You guided Kiro to add a new
/api/quoteendpoint to your Flask application. - You tested the new feature to ensure it works as expected.
- You tackled a mini-challenge, further refining Kiro’s output.
- You gained insights into common pitfalls like vague instructions and context issues, along with strategies for troubleshooting.
This project-based approach highlights how Kiro can be an invaluable tool for accelerating development and maintaining focus on higher-level architectural concerns. In the next chapter, we’ll delve deeper into Kiro’s advanced features, exploring how it can assist with more complex tasks like refactoring, performance optimization, and integrating with other AWS services.
References
- AWS Kiro Official GitHub Repository
- Flask Official Documentation
- AWS Blogs: Transform DevOps practice with Kiro AI-powered agents
- AWS Builder Library: Building “The Referee” with Kiro
- Python Official Documentation
This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.