<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Richard Atodo</title>
    <description>The latest articles on DEV Community by Richard Atodo (@richard_atodo).</description>
    <link>https://dev.to/richard_atodo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2335610%2F731836a6-4162-4626-b41e-99cc5d20cfc7.jpg</url>
      <title>DEV Community: Richard Atodo</title>
      <link>https://dev.to/richard_atodo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/richard_atodo"/>
    <language>en</language>
    <item>
      <title>🔍 Building a Local RAG Pipeline for an AI DevOps Incident Copilot</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Wed, 18 Nov 2026 12:24:59 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-a-local-rag-pipeline-for-an-ai-devops-incident-copilot-2ej1</link>
      <guid>https://dev.to/richard_atodo/building-a-local-rag-pipeline-for-an-ai-devops-incident-copilot-2ej1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;An AI-powered DevOps incident assistant needs more than an LLM.&lt;/p&gt;

&lt;p&gt;When an application experiences an outage, the system needs access to relevant operational knowledge: troubleshooting procedures, infrastructure documentation, deployment guidance, error explanations, and historical incident information.&lt;/p&gt;

&lt;p&gt;Without that knowledge, an LLM may generate plausible but generic suggestions that do not reflect the actual environment or established operational procedures.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;IncidentCopilot&lt;/strong&gt;, Milestone 6 focused on building the local &lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt; foundation that will eventually supply relevant technical knowledge to the incident diagnosis engine.&lt;/p&gt;

&lt;p&gt;The goal was to create a pipeline capable of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loading Markdown runbooks&lt;/li&gt;
&lt;li&gt;Processing them into meaningful chunks&lt;/li&gt;
&lt;li&gt;Generating local embeddings&lt;/li&gt;
&lt;li&gt;Storing vectors in a vector database&lt;/li&gt;
&lt;li&gt;Retrieving relevant knowledge using natural-language search&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Importantly, this milestone deliberately stopped short of AI diagnosis.&lt;/p&gt;

&lt;p&gt;The objective was to build and verify retrieval independently before introducing LLM reasoning.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Architecture Overview
&lt;/h2&gt;

&lt;p&gt;The Milestone 6 pipeline consists of five stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Document loading&lt;/li&gt;
&lt;li&gt;Document chunking&lt;/li&gt;
&lt;li&gt;Embedding generation&lt;/li&gt;
&lt;li&gt;Vector storage&lt;/li&gt;
&lt;li&gt;Similarity retrieval
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A[Markdown Runbooks] --&amp;gt; B[Document Loader]
    B --&amp;gt; C[Section-Aware Chunker]
    C --&amp;gt; D[Embedding Provider]
    D --&amp;gt; E[Qdrant Vector Database]

    F[User Search Query] --&amp;gt; G[Query Embedding]
    G --&amp;gt; H[Vector Similarity Search]
    E --&amp;gt; H
    H --&amp;gt; I[Retrieved Knowledge Chunks]
    I --&amp;gt; J[API Response]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The indexing pipeline and search pipeline share the same embedding model so that both document vectors and query vectors exist within the same embedding space.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 Why RAG?
&lt;/h2&gt;

&lt;p&gt;Retrieval-Augmented Generation combines information retrieval with language-model generation.&lt;/p&gt;

&lt;p&gt;Instead of relying entirely on knowledge embedded in a model's training data, a RAG system retrieves relevant external information and supplies it as context.&lt;/p&gt;

&lt;p&gt;The process typically looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User submits a question&lt;/li&gt;
&lt;li&gt;Question is converted into an embedding&lt;/li&gt;
&lt;li&gt;The embedding is compared against stored document embeddings&lt;/li&gt;
&lt;li&gt;Relevant document chunks are retrieved&lt;/li&gt;
&lt;li&gt;Retrieved content is supplied to an LLM&lt;/li&gt;
&lt;li&gt;The LLM generates a grounded response&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this milestone, I implemented &lt;strong&gt;steps 1–4 only&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The API currently exposes retrieved content directly. LLM generation will be introduced in a future milestone.&lt;/p&gt;

&lt;p&gt;This separation allows retrieval quality to be tested independently from model behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Adding Qdrant
&lt;/h2&gt;

&lt;p&gt;I selected &lt;strong&gt;Qdrant&lt;/strong&gt; as the vector database for local development.&lt;/p&gt;

&lt;p&gt;Qdrant provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vector storage&lt;/li&gt;
&lt;li&gt;Similarity search&lt;/li&gt;
&lt;li&gt;Payload metadata&lt;/li&gt;
&lt;li&gt;Containerized deployment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It aligns well with IncidentCopilot's local-first architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Configuration
&lt;/h3&gt;

&lt;p&gt;Persistent storage is configured using a named volume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;qdrant_data:/qdrant/storage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures vector data survives container recreation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exposed Ports
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;6333&lt;/code&gt; → HTTP API&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;6334&lt;/code&gt; → gRPC API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The backend waits for Qdrant's health check before startup to ensure the vector database is available.&lt;/p&gt;

&lt;h3&gt;
  
  
  Network Configuration
&lt;/h3&gt;

&lt;p&gt;Inside Docker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://qdrant:6333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Host machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:6333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keeping these values separate avoids confusion between container networking and host networking.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Choosing Local Embeddings
&lt;/h2&gt;

&lt;p&gt;IncidentCopilot is designed to operate without paid cloud APIs.&lt;/p&gt;

&lt;p&gt;Embeddings allow the system to compare meaning rather than relying on exact keyword matching.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"The application is unavailable"&lt;/li&gt;
&lt;li&gt;"The service is down"&lt;/li&gt;
&lt;li&gt;"The upstream server cannot be reached"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although worded differently, these statements describe similar concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embedding Model
&lt;/h3&gt;

&lt;p&gt;The project uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sentence-transformers/all-MiniLM-L6-v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;via &lt;strong&gt;FastEmbed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Vector size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;384 dimensions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Provider Abstraction
&lt;/h2&gt;

&lt;p&gt;The embedding layer uses a provider-neutral interface:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmbeddingProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Protocol&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nd"&gt;@property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dimension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;embed_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;texts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;embed_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps the RAG system independent from any specific embedding implementation.&lt;/p&gt;

&lt;p&gt;Future providers can be substituted without changing retrieval logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Lazy Model Loading
&lt;/h2&gt;

&lt;p&gt;The embedding model is loaded only when needed.&lt;/p&gt;

&lt;p&gt;Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster application startup&lt;/li&gt;
&lt;li&gt;Reduced memory usage&lt;/li&gt;
&lt;li&gt;Avoids unnecessary initialization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model instance is cached after first use so subsequent requests do not repeatedly load model weights.&lt;/p&gt;




&lt;h2&gt;
  
  
  📄 Building the Document Loader
&lt;/h2&gt;

&lt;p&gt;The initial knowledge base consists of Markdown runbooks.&lt;/p&gt;

&lt;p&gt;The loader validates that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The runbooks directory exists&lt;/li&gt;
&lt;li&gt;The path is a directory&lt;/li&gt;
&lt;li&gt;Markdown files are not empty&lt;/li&gt;
&lt;li&gt;Documents begin with an H1 heading&lt;/li&gt;
&lt;li&gt;Titles are not empty&lt;/li&gt;
&lt;li&gt;Documents contain content after the title&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Document Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MarkdownDocument&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;document_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;source_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Deterministic Document IDs
&lt;/h2&gt;

&lt;p&gt;Document IDs are derived from the file path using SHA-256.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runbooks/nginx-502.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same file path always generates the same document ID.&lt;/p&gt;

&lt;p&gt;This means document identity remains stable even when content changes.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✂️ Document Chunking
&lt;/h2&gt;

&lt;p&gt;Embedding an entire runbook as one vector reduces retrieval precision.&lt;/p&gt;

&lt;p&gt;Queries often need a specific troubleshooting step rather than an entire document.&lt;/p&gt;

&lt;p&gt;Chunking allows retrieval of relevant sections instead of full runbooks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Section-Aware Chunking?
&lt;/h2&gt;

&lt;p&gt;An early implementation revealed an issue:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chunks sometimes contained multiple sections&lt;/li&gt;
&lt;li&gt;Metadata represented only the final section&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This reduced retrieval quality.&lt;/p&gt;

&lt;p&gt;The revised chunker treats Markdown sections independently.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# Nginx 502 Troubleshooting
&lt;/span&gt;
&lt;span class="gu"&gt;## Overview
&lt;/span&gt;
An Nginx 502 error indicates an invalid upstream response.

&lt;span class="gu"&gt;## Common Causes
&lt;/span&gt;
&lt;span class="k"&gt;- &lt;/span&gt;Upstream service unavailable
&lt;span class="k"&gt;- &lt;/span&gt;Incorrect upstream configuration

&lt;span class="gu"&gt;## Investigation Steps
&lt;/span&gt;
&lt;span class="k"&gt;- &lt;/span&gt;Inspect Nginx logs
&lt;span class="k"&gt;- &lt;/span&gt;Verify upstream connectivity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each section becomes a logical retrieval unit.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chunk Metadata
&lt;/h2&gt;

&lt;p&gt;Each chunk retains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document ID&lt;/li&gt;
&lt;li&gt;Document title&lt;/li&gt;
&lt;li&gt;Source path&lt;/li&gt;
&lt;li&gt;Chunk index&lt;/li&gt;
&lt;li&gt;Section&lt;/li&gt;
&lt;li&gt;Content&lt;/li&gt;
&lt;li&gt;Chunk ID&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This metadata provides context during retrieval.&lt;/p&gt;




&lt;h2&gt;
  
  
  Word-Boundary Preservation
&lt;/h2&gt;

&lt;p&gt;A second issue emerged when chunks split words.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;restartingor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hurts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Readability&lt;/li&gt;
&lt;li&gt;Embedding quality&lt;/li&gt;
&lt;li&gt;Retrieval relevance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The updated chunker now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Splits on complete words&lt;/li&gt;
&lt;li&gt;Preserves overlap using whole-word boundaries&lt;/li&gt;
&lt;li&gt;Maintains readability while retaining context&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Chunk Configuration
&lt;/h2&gt;

&lt;p&gt;Chunking behavior is configurable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chunk size&lt;/li&gt;
&lt;li&gt;Chunk overlap&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Validation ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chunk size &amp;gt; 0&lt;/li&gt;
&lt;li&gt;Overlap ≥ 0&lt;/li&gt;
&lt;li&gt;Overlap &amp;lt; chunk size&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows future tuning without changing implementation logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  🗄️ Vector Storage Design
&lt;/h2&gt;

&lt;p&gt;Qdrant stores each chunk as a vector point with metadata.&lt;/p&gt;

&lt;p&gt;Payload fields include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chunk_id
document_id
document_type
title
content
source_path
chunk_index
section
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Metadata enables explainable retrieval.&lt;/p&gt;

&lt;p&gt;The API can return:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieved content&lt;/li&gt;
&lt;li&gt;Document title&lt;/li&gt;
&lt;li&gt;Source runbook&lt;/li&gt;
&lt;li&gt;Relevant section&lt;/li&gt;
&lt;li&gt;Similarity score&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Deterministic Point IDs
&lt;/h2&gt;

&lt;p&gt;Qdrant point IDs are generated using UUID5 derived from the chunk ID.&lt;/p&gt;

&lt;p&gt;Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Predictable indexing&lt;/li&gt;
&lt;li&gt;Idempotent upserts&lt;/li&gt;
&lt;li&gt;No accidental duplication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Re-indexing the same content updates existing points instead of creating new ones.&lt;/p&gt;




&lt;h2&gt;
  
  
  Replacing Obsolete Chunks
&lt;/h2&gt;

&lt;p&gt;Runbooks evolve over time.&lt;/p&gt;

&lt;p&gt;Simply upserting new chunks would leave outdated chunks searchable.&lt;/p&gt;

&lt;p&gt;To solve this, indexing performs document-level replacement:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Retrieve existing point IDs&lt;/li&gt;
&lt;li&gt;Generate IDs for new chunks&lt;/li&gt;
&lt;li&gt;Upsert new chunks&lt;/li&gt;
&lt;li&gt;Identify obsolete points&lt;/li&gt;
&lt;li&gt;Delete obsolete points&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This ensures search results remain current.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ The RAG Service
&lt;/h2&gt;

&lt;p&gt;The RAG service orchestrates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document loading&lt;/li&gt;
&lt;li&gt;Chunking&lt;/li&gt;
&lt;li&gt;Embedding generation&lt;/li&gt;
&lt;li&gt;Vector storage&lt;/li&gt;
&lt;li&gt;Retrieval&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Indexing Workflow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Load Documents
      ↓
Chunk Documents
      ↓
Generate Embeddings
      ↓
Validate Embedding Count
      ↓
Group Chunks by Document
      ↓
Replace Chunks in Vector Store
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Embeddings are generated before modifying Qdrant, reducing the risk of partial indexing failures.&lt;/p&gt;




&lt;h3&gt;
  
  
  Search Workflow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Validate Query
      ↓
Generate Query Embedding
      ↓
Search Qdrant
      ↓
Return Ranked Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invalid queries and invalid limits are rejected.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 API Endpoints
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Index Runbooks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;rag&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"documents_indexed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"chunks_indexed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Search Runbooks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;rag&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Nginx returns 502 because the upstream application is unavailable"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Query&lt;/li&gt;
&lt;li&gt;Result count&lt;/li&gt;
&lt;li&gt;Retrieved chunks&lt;/li&gt;
&lt;li&gt;Metadata&lt;/li&gt;
&lt;li&gt;Similarity scores&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📚 Building the Initial Knowledge Base
&lt;/h2&gt;

&lt;p&gt;Five operational runbooks were created:&lt;/p&gt;

&lt;h3&gt;
  
  
  Nginx 502 Bad Gateway
&lt;/h3&gt;

&lt;p&gt;Covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upstream availability&lt;/li&gt;
&lt;li&gt;Bad upstream configuration&lt;/li&gt;
&lt;li&gt;Docker networking&lt;/li&gt;
&lt;li&gt;Connection timeouts&lt;/li&gt;
&lt;li&gt;Log analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database Connection Failure
&lt;/h3&gt;

&lt;p&gt;Covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database availability&lt;/li&gt;
&lt;li&gt;Authentication issues&lt;/li&gt;
&lt;li&gt;Connection configuration&lt;/li&gt;
&lt;li&gt;Network restrictions&lt;/li&gt;
&lt;li&gt;Connection pool exhaustion&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Kubernetes CrashLoopBackOff
&lt;/h3&gt;

&lt;p&gt;Covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repeated container restarts&lt;/li&gt;
&lt;li&gt;Pod inspection&lt;/li&gt;
&lt;li&gt;Exit codes&lt;/li&gt;
&lt;li&gt;Resource limits&lt;/li&gt;
&lt;li&gt;Health probes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Docker Container Restart
&lt;/h3&gt;

&lt;p&gt;Covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unexpected exits&lt;/li&gt;
&lt;li&gt;Restart policies&lt;/li&gt;
&lt;li&gt;OOM events&lt;/li&gt;
&lt;li&gt;Health check failures&lt;/li&gt;
&lt;li&gt;Host resource issues&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  GitHub Actions Workflow Failure
&lt;/h3&gt;

&lt;p&gt;Covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Workflow syntax&lt;/li&gt;
&lt;li&gt;Secrets&lt;/li&gt;
&lt;li&gt;Permissions&lt;/li&gt;
&lt;li&gt;Dependency failures&lt;/li&gt;
&lt;li&gt;Runner configuration&lt;/li&gt;
&lt;li&gt;Deployment authentication&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧪 Testing Strategy
&lt;/h2&gt;

&lt;p&gt;Testing covered multiple layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Document Tests
&lt;/h3&gt;

&lt;p&gt;Validates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document loading&lt;/li&gt;
&lt;li&gt;Empty directories&lt;/li&gt;
&lt;li&gt;Empty files&lt;/li&gt;
&lt;li&gt;Missing titles&lt;/li&gt;
&lt;li&gt;Missing content&lt;/li&gt;
&lt;li&gt;Metadata preservation&lt;/li&gt;
&lt;li&gt;Chunk generation&lt;/li&gt;
&lt;li&gt;Deterministic IDs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Service Tests
&lt;/h3&gt;

&lt;p&gt;Validates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Indexing&lt;/li&gt;
&lt;li&gt;Retrieval&lt;/li&gt;
&lt;li&gt;Empty retrieval&lt;/li&gt;
&lt;li&gt;Repeated indexing&lt;/li&gt;
&lt;li&gt;Chunk replacement&lt;/li&gt;
&lt;li&gt;Invalid queries&lt;/li&gt;
&lt;li&gt;Invalid limits&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Vector Store Tests
&lt;/h3&gt;

&lt;p&gt;Validates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collection creation&lt;/li&gt;
&lt;li&gt;Upserts&lt;/li&gt;
&lt;li&gt;Metadata persistence&lt;/li&gt;
&lt;li&gt;Similarity ordering&lt;/li&gt;
&lt;li&gt;Vector validation&lt;/li&gt;
&lt;li&gt;Idempotent indexing&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  API Tests
&lt;/h3&gt;

&lt;p&gt;Validates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Successful indexing&lt;/li&gt;
&lt;li&gt;Search requests&lt;/li&gt;
&lt;li&gt;Validation failures&lt;/li&gt;
&lt;li&gt;Empty results&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Test Results
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;103 passed
0 failed
1 warning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Live Integration Verification
&lt;/h2&gt;

&lt;p&gt;Infrastructure verification confirmed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PostgreSQL healthy&lt;/li&gt;
&lt;li&gt;Backend running&lt;/li&gt;
&lt;li&gt;Qdrant healthy&lt;/li&gt;
&lt;li&gt;Runbooks mounted&lt;/li&gt;
&lt;li&gt;Embedding model downloaded&lt;/li&gt;
&lt;li&gt;Live indexing successful&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Indexing Result
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"documents_indexed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"chunks_indexed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repeated indexing produced the same result.&lt;/p&gt;

&lt;p&gt;Qdrant verification confirmed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Indexed points: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No duplicate vectors were created.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Retrieval Quality
&lt;/h2&gt;

&lt;p&gt;Five live natural-language queries were executed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query Category&lt;/th&gt;
&lt;th&gt;Correct Runbook Retrieved First&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nginx 502&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database Connectivity&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kubernetes CrashLoopBackOff&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Docker Restart&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub Actions Failure&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Retrieved results included both relevant content and supporting metadata.&lt;/p&gt;




&lt;h2&gt;
  
  
  📖 Lessons Learned
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Retrieval Quality Depends on Documentation Quality
&lt;/h3&gt;

&lt;p&gt;Even a high-quality vector database cannot compensate for poor documentation.&lt;/p&gt;

&lt;p&gt;Good retrieval requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear runbooks&lt;/li&gt;
&lt;li&gt;Meaningful headings&lt;/li&gt;
&lt;li&gt;Logical sections&lt;/li&gt;
&lt;li&gt;Useful metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Chunking Is Critical
&lt;/h3&gt;

&lt;p&gt;Poor chunking can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Split words&lt;/li&gt;
&lt;li&gt;Remove context&lt;/li&gt;
&lt;li&gt;Produce misleading metadata&lt;/li&gt;
&lt;li&gt;Harm retrieval quality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Section-aware chunking proved far more effective for operational documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deterministic IDs Simplify Indexing
&lt;/h3&gt;

&lt;p&gt;Stable identifiers make repeated indexing predictable and prevent duplication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local-First Architecture Matters
&lt;/h3&gt;

&lt;p&gt;Using FastEmbed and Qdrant provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offline-capable development&lt;/li&gt;
&lt;li&gt;Lower operating costs&lt;/li&gt;
&lt;li&gt;Better control of operational data&lt;/li&gt;
&lt;li&gt;Reproducible environments&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Test Isolation Remains Important
&lt;/h3&gt;

&lt;p&gt;The backend test suite continues to use a dedicated PostgreSQL test database.&lt;/p&gt;

&lt;p&gt;This ensures tests never run against development data.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Current Limitations
&lt;/h2&gt;

&lt;p&gt;The system retrieves operational knowledge but does not yet generate diagnoses.&lt;/p&gt;

&lt;p&gt;It does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analyze incidents using an LLM&lt;/li&gt;
&lt;li&gt;Generate root-cause conclusions&lt;/li&gt;
&lt;li&gt;Combine retrieved knowledge with correlation data&lt;/li&gt;
&lt;li&gt;Index historical incidents&lt;/li&gt;
&lt;li&gt;Perform reranking&lt;/li&gt;
&lt;li&gt;Benchmark retrieval quality formally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The retrieval layer should currently be treated as an evidence source, not a diagnostic authority.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔮 What Comes Next?
&lt;/h2&gt;

&lt;p&gt;The next milestone introduces a local LLM through &lt;strong&gt;Ollama&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The diagnosis pipeline will build upon:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incident lifecycle management&lt;/li&gt;
&lt;li&gt;Log ingestion&lt;/li&gt;
&lt;li&gt;Deterministic correlation&lt;/li&gt;
&lt;li&gt;Incident timelines&lt;/li&gt;
&lt;li&gt;RAG retrieval&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The future system will clearly distinguish:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Observed facts&lt;/li&gt;
&lt;li&gt;Correlation signals&lt;/li&gt;
&lt;li&gt;Retrieved guidance&lt;/li&gt;
&lt;li&gt;AI-generated hypotheses&lt;/li&gt;
&lt;li&gt;Recommendations&lt;/li&gt;
&lt;li&gt;Missing evidence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is not to make the AI sound confident.&lt;/p&gt;

&lt;p&gt;The goal is to produce &lt;strong&gt;explainable, evidence-grounded incident analysis&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;Milestone 6 successfully established a local RAG infrastructure for IncidentCopilot.&lt;/p&gt;

&lt;p&gt;The platform can now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load Markdown runbooks&lt;/li&gt;
&lt;li&gt;Create section-aware chunks&lt;/li&gt;
&lt;li&gt;Generate local embeddings&lt;/li&gt;
&lt;li&gt;Store vectors in Qdrant&lt;/li&gt;
&lt;li&gt;Retrieve relevant operational knowledge through an API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All five initial runbooks were indexed and verified through live retrieval.&lt;/p&gt;

&lt;p&gt;Repeated indexing produced the expected &lt;strong&gt;30 vector points&lt;/strong&gt; without duplication, and the full backend suite completed successfully with &lt;strong&gt;103 passing tests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This milestone establishes the knowledge retrieval layer required for the next stage:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Locally powered, evidence-grounded AI incident diagnosis.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;https://github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next:&lt;/strong&gt; Milestone 7 — Ollama-Powered Incident Diagnosis&lt;/p&gt;

</description>
      <category>devops</category>
      <category>rag</category>
      <category>qdrant</category>
    </item>
    <item>
      <title>🚨 Building an Incident Lifecycle and Timeline Engine with FastAPI and PostgreSQL</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Thu, 05 Nov 2026 11:36:10 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-an-incident-lifecycle-and-timeline-engine-with-fastapi-and-postgresql-3hm</link>
      <guid>https://dev.to/richard_atodo/building-an-incident-lifecycle-and-timeline-engine-with-fastapi-and-postgresql-3hm</guid>
      <description>&lt;p&gt;&lt;em&gt;Milestone 5 of IncidentCopilot: moving from log correlation to structured incident management.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Collecting logs is only part of incident investigation.&lt;/p&gt;

&lt;p&gt;A useful incident management system needs to do more than store operational events. It should provide a structured way to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create incidents&lt;/li&gt;
&lt;li&gt;Track investigation progress&lt;/li&gt;
&lt;li&gt;Associate supporting evidence&lt;/li&gt;
&lt;li&gt;Build a timeline of what happened&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;Milestone 5&lt;/strong&gt; of &lt;strong&gt;IncidentCopilot&lt;/strong&gt;, I focused on implementing this foundation using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;SQLAlchemy&lt;/li&gt;
&lt;li&gt;The deterministic correlation engine introduced in Milestone 4&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One important design decision remained unchanged:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Build deterministic systems first. Introduce AI only after the evidence pipeline is reliable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At this stage, the application reports what it has observed and what its correlation engine has inferred. It does not generate AI diagnoses or treat correlations as proven causes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 From Log Correlation to Incident Management
&lt;/h2&gt;

&lt;p&gt;Previous milestones established:&lt;/p&gt;

&lt;p&gt;✅ FastAPI backend and PostgreSQL persistence&lt;/p&gt;

&lt;p&gt;✅ Multi-source log ingestion&lt;/p&gt;

&lt;p&gt;✅ Deterministic log correlation&lt;/p&gt;

&lt;p&gt;However, correlated logs alone do not provide a complete investigation workflow.&lt;/p&gt;

&lt;p&gt;The next step was adding:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Incident lifecycle management&lt;/li&gt;
&lt;li&gt;Log-to-incident association&lt;/li&gt;
&lt;li&gt;Timeline generation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Together, these capabilities allow operational evidence to be organized around a specific incident.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Designing the Incident Lifecycle
&lt;/h2&gt;

&lt;p&gt;I implemented three incident states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPEN
INVESTIGATING
RESOLVED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workflow is intentionally explicit.&lt;/p&gt;

&lt;p&gt;An incident:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starts in &lt;code&gt;OPEN&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Moves to &lt;code&gt;INVESTIGATING&lt;/code&gt; when an operator begins investigation&lt;/li&gt;
&lt;li&gt;Moves to &lt;code&gt;RESOLVED&lt;/code&gt; when the incident is closed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Supported Transitions
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Current State&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;OPEN&lt;/td&gt;
&lt;td&gt;Investigate&lt;/td&gt;
&lt;td&gt;INVESTIGATING&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OPEN&lt;/td&gt;
&lt;td&gt;Resolve&lt;/td&gt;
&lt;td&gt;RESOLVED&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;INVESTIGATING&lt;/td&gt;
&lt;td&gt;Resolve&lt;/td&gt;
&lt;td&gt;RESOLVED&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;INVESTIGATING&lt;/td&gt;
&lt;td&gt;Investigate Again&lt;/td&gt;
&lt;td&gt;INVESTIGATING&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RESOLVED&lt;/td&gt;
&lt;td&gt;Resolve Again&lt;/td&gt;
&lt;td&gt;RESOLVED&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RESOLVED&lt;/td&gt;
&lt;td&gt;Investigate&lt;/td&gt;
&lt;td&gt;Rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A key design choice:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Attaching new evidence should not automatically change an incident's operational state.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Log association and lifecycle transitions remain separate operations.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Idempotency and Lifecycle Safety
&lt;/h2&gt;

&lt;p&gt;Two important behaviors were implemented.&lt;/p&gt;

&lt;h3&gt;
  
  
  Repeated Investigation
&lt;/h3&gt;

&lt;p&gt;Calling the investigation endpoint multiple times does not create duplicate state transitions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Repeated Resolution
&lt;/h3&gt;

&lt;p&gt;When an incident is resolved, the system records its:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ended_at
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;timestamp.&lt;/p&gt;

&lt;p&gt;Subsequent resolution requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not overwrite the original timestamp&lt;/li&gt;
&lt;li&gt;Do not create additional transitions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attempting to move a resolved incident back into investigation returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;409 Conflict
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps lifecycle behavior predictable for both API consumers and future frontend components.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Associating Logs with Incidents
&lt;/h2&gt;

&lt;p&gt;An incident becomes useful when all relevant operational evidence can be reviewed in one place.&lt;/p&gt;

&lt;p&gt;I added an endpoint that accepts multiple log IDs and associates them with an incident.&lt;/p&gt;

&lt;p&gt;The implementation supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple logs per request&lt;/li&gt;
&lt;li&gt;Duplicate detection&lt;/li&gt;
&lt;li&gt;Validation of unknown log IDs&lt;/li&gt;
&lt;li&gt;Preservation of existing associations&lt;/li&gt;
&lt;li&gt;No automatic lifecycle transitions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The service retrieves all logs currently associated with the incident and combines them with newly attached logs.&lt;/p&gt;

&lt;p&gt;It then re-evaluates the complete set using the correlation engine.&lt;/p&gt;

&lt;p&gt;This is important because newly attached evidence can affect the strongest known relationships among previously associated logs.&lt;/p&gt;




&lt;h2&gt;
  
  
  ➡️ Preserving Correlation Direction
&lt;/h2&gt;

&lt;p&gt;The correlation engine models relationships directionally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;log_id          = later event
related_log_id  = earlier event
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That direction is preserved when correlation metadata is stored.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because temporal ordering contributes to the meaning of a correlation.&lt;/p&gt;

&lt;p&gt;A relationship between two events does not automatically establish causation.&lt;/p&gt;

&lt;p&gt;Preserving direction helps maintain that distinction.&lt;/p&gt;




&lt;h2&gt;
  
  
  📅 Building the Incident Timeline
&lt;/h2&gt;

&lt;p&gt;One of the most important features of this milestone is the incident timeline.&lt;/p&gt;

&lt;p&gt;The timeline distinguishes between:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Observed events&lt;/li&gt;
&lt;li&gt;Derived events&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Observed Log Events
&lt;/h3&gt;

&lt;p&gt;Observed events represent actual persisted logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;observed_log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each event includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timestamp&lt;/li&gt;
&lt;li&gt;Log ID&lt;/li&gt;
&lt;li&gt;Source&lt;/li&gt;
&lt;li&gt;Severity&lt;/li&gt;
&lt;li&gt;Service&lt;/li&gt;
&lt;li&gt;Message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These records come directly from ingested operational evidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Correlation Events
&lt;/h3&gt;

&lt;p&gt;Correlation events represent relationships generated by the deterministic correlation engine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;correlation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each event includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Later log ID&lt;/li&gt;
&lt;li&gt;Earlier log ID&lt;/li&gt;
&lt;li&gt;Relationship type&lt;/li&gt;
&lt;li&gt;Relevance score&lt;/li&gt;
&lt;li&gt;Correlation explanation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These events are derived information rather than raw observations.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Distinction Matters
&lt;/h2&gt;

&lt;p&gt;Imagine a payment service experiencing database connectivity issues.&lt;/p&gt;

&lt;p&gt;The system may observe:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A database connection refusal&lt;/li&gt;
&lt;li&gt;A payment API exception shortly afterward&lt;/li&gt;
&lt;li&gt;Additional service-level errors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The timeline can display:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raw log evidence&lt;/li&gt;
&lt;li&gt;Deterministic correlation signals&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows operators to distinguish:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happened&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;from&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the system inferred&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That distinction becomes even more important as future milestones introduce AI-generated diagnoses and recommendations.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⏱️ Timeline Ordering
&lt;/h2&gt;

&lt;p&gt;Timeline events are sorted chronologically.&lt;/p&gt;

&lt;p&gt;When an observed log event and a correlation event share the same timestamp, the observed log is displayed first.&lt;/p&gt;

&lt;p&gt;This creates a more natural investigative flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Show the evidence&lt;/li&gt;
&lt;li&gt;Show the interpretation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Correlation events inherit the timestamp of the later event in the relationship, keeping derived information anchored to the event that completed the correlation pair.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 API Endpoints
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Endpoint&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create an incident&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List incidents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents/{incident_id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retrieve an incident&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents/{incident_id}/events&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retrieve timeline events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents/{incident_id}/logs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Associate logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents/{incident_id}/investigate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Start investigation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/incidents/{incident_id}/resolve&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Resolve incident&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The API layer handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Request validation&lt;/li&gt;
&lt;li&gt;HTTP concerns&lt;/li&gt;
&lt;li&gt;Exception mapping&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The service layer owns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lifecycle management&lt;/li&gt;
&lt;li&gt;Correlation refresh logic&lt;/li&gt;
&lt;li&gt;Timeline generation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation keeps business logic out of route handlers and improves testability.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Testing the Implementation
&lt;/h2&gt;

&lt;p&gt;Testing covered both successful workflows and invalid scenarios.&lt;/p&gt;

&lt;p&gt;The suite validates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incident creation&lt;/li&gt;
&lt;li&gt;Invalid input handling&lt;/li&gt;
&lt;li&gt;Title normalization&lt;/li&gt;
&lt;li&gt;Incident retrieval and listing&lt;/li&gt;
&lt;li&gt;Lifecycle transitions&lt;/li&gt;
&lt;li&gt;Repeated lifecycle actions&lt;/li&gt;
&lt;li&gt;Invalid transitions&lt;/li&gt;
&lt;li&gt;Log association&lt;/li&gt;
&lt;li&gt;Duplicate log detection&lt;/li&gt;
&lt;li&gt;Timeline generation&lt;/li&gt;
&lt;li&gt;Correlation ordering&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Result
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;60 passed, 1 warning in 2.53s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Additional Verification
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff &lt;span class="nt"&gt;--check&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ No whitespace issues detected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;alembic check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ No new upgrade operations detected&lt;/p&gt;

&lt;p&gt;No database migration was required because the existing schema already supported the incident and log relationships.&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Key Lessons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Keep Lifecycle Changes Explicit
&lt;/h3&gt;

&lt;p&gt;Attaching evidence should never silently change incident state.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Separate Evidence from Interpretation
&lt;/h3&gt;

&lt;p&gt;Raw logs and correlation signals represent fundamentally different types of information.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Keep Correlation Deterministic
&lt;/h3&gt;

&lt;p&gt;The correlation engine remains independent of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI&lt;/li&gt;
&lt;li&gt;PostgreSQL queries&lt;/li&gt;
&lt;li&gt;Vector databases&lt;/li&gt;
&lt;li&gt;LLM integrations&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Correlation Scores Are Not Probabilities
&lt;/h3&gt;

&lt;p&gt;A relevance score is a heuristic.&lt;/p&gt;

&lt;p&gt;It indicates potential importance but does not prove causation.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Refresh Correlations When Evidence Changes
&lt;/h3&gt;

&lt;p&gt;Newly associated logs can alter the strongest known relationships among existing evidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Test State Transitions, Not Just Endpoints
&lt;/h3&gt;

&lt;p&gt;A successful HTTP response is not enough.&lt;/p&gt;

&lt;p&gt;Lifecycle correctness requires explicit testing of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Idempotency&lt;/li&gt;
&lt;li&gt;Invalid transitions&lt;/li&gt;
&lt;li&gt;State persistence&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔮 What's Next?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Milestone 6: Qdrant Integration &amp;amp; Evidence Retrieval&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With incident lifecycle management and timeline generation complete, the next step is introducing vector search and evidence retrieval.&lt;/p&gt;

&lt;p&gt;This milestone will establish the retrieval foundation needed for future RAG workflows.&lt;/p&gt;

&lt;p&gt;AI-powered diagnosis remains intentionally separate. Before asking a language model to interpret evidence, the system must first be able to retrieve and organize that evidence reliably.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;Milestone 5 moves IncidentCopilot beyond ingestion and correlation into structured incident management.&lt;/p&gt;

&lt;p&gt;The platform can now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create incidents&lt;/li&gt;
&lt;li&gt;Manage lifecycle transitions&lt;/li&gt;
&lt;li&gt;Associate operational evidence&lt;/li&gt;
&lt;li&gt;Generate chronological timelines&lt;/li&gt;
&lt;li&gt;Distinguish observed events from derived relationships&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most importantly, it reinforces a principle that has guided the project from the beginning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A reliable AI incident assistant starts with a reliable engineering foundation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before introducing AI-generated diagnoses, the system must be able to organize evidence, preserve chronology, and clearly communicate what it knows versus what it has inferred.&lt;/p&gt;

&lt;p&gt;That is the foundation Milestone 5 establishes.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://www.github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;https://www.github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next:&lt;/strong&gt; Milestone 6 — Qdrant Integration &amp;amp; Evidence Retrieval&lt;/p&gt;

</description>
      <category>ai</category>
      <category>fastapi</category>
      <category>backend</category>
      <category>postgressql</category>
    </item>
    <item>
      <title>🔎 Building IncidentCopilot: Designing a Deterministic Log Correlation Engine</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Sun, 18 Oct 2026 20:31:14 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-incidentcopilot-designing-a-deterministic-log-correlation-engine-10i7</link>
      <guid>https://dev.to/richard_atodo/building-incidentcopilot-designing-a-deterministic-log-correlation-engine-10i7</guid>
      <description>&lt;p&gt;&lt;em&gt;Milestone 4 of IncidentCopilot — an open-source, local-first AI DevOps Incident Copilot&lt;/em&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Introduction
&lt;/h2&gt;

&lt;p&gt;Logs are plentiful during outages — the challenge is &lt;strong&gt;understanding what they mean together.&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nginx → HTTP 502 errors
&lt;/li&gt;
&lt;li&gt;Applications → DB connection timeouts
&lt;/li&gt;
&lt;li&gt;Docker → container exits
&lt;/li&gt;
&lt;li&gt;Kubernetes → failed readiness probes
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;IncidentCopilot is being built to help developers &lt;strong&gt;collect, correlate, and explain logs&lt;/strong&gt; before introducing AI.  &lt;/p&gt;

&lt;p&gt;Milestone 4 focused on implementing a &lt;strong&gt;deterministic log correlation engine&lt;/strong&gt; that evaluates signals and produces explainable relationships.  &lt;/p&gt;




&lt;h2&gt;
  
  
  1️⃣ From Ingestion to Correlation
&lt;/h2&gt;

&lt;p&gt;Milestone 3 handled ingestion for five sources: Nginx, Kubernetes, Docker, application logs, GitHub Actions.  &lt;/p&gt;

&lt;p&gt;Correlation adds context: are events related, or just coincidental?  &lt;/p&gt;




&lt;h2&gt;
  
  
  2️⃣ Common Event Representation
&lt;/h2&gt;

&lt;p&gt;The engine uses a &lt;strong&gt;typed event contract&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;id&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;source&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;timestamp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;severity&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;service&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;event_type&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;message&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;metadata&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;raw_message&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps correlation logic independent of the database.  &lt;/p&gt;




&lt;h2&gt;
  
  
  3️⃣ Correlation Signals
&lt;/h2&gt;

&lt;p&gt;Five weighted signals drive relevance:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Temporal proximity (25%)&lt;/strong&gt; → closeness in time
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service relationships (25%)&lt;/strong&gt; → shared service identities
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error signatures (25%)&lt;/strong&gt; → recognizable failure patterns (&lt;code&gt;connection refused&lt;/code&gt;, &lt;code&gt;CrashLoopBackOff&lt;/code&gt;, &lt;code&gt;HTTP 502&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Severity weighting (15%)&lt;/strong&gt; → critical events matter more
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Causal ordering (10%)&lt;/strong&gt; → earlier warnings/errors may precede failures
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4️⃣ Calculating Relevance
&lt;/h2&gt;

&lt;p&gt;Weights are explicit heuristics, not probabilities:  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Signal&lt;/th&gt;
&lt;th&gt;Weight&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Temporal proximity&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service relationship&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error signature&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Severity&lt;/td&gt;
&lt;td&gt;0.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ordering&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;S = 0.25St + 0.25Sv + 0.25Se + 0.15Ss + 0.10So
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scores are capped at 1.0. Timing alone does not create correlations.  &lt;/p&gt;




&lt;h2&gt;
  
  
  5️⃣ Explainability
&lt;/h2&gt;

&lt;p&gt;The engine returns structured signals:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;log_id&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;related_log_id&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;relevance_score&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;relationship_type&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reason&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Explanations include time differences, matching services, shared error signatures, and ordering.  &lt;/p&gt;

&lt;p&gt;This makes correlations &lt;strong&gt;transparent and inspectable&lt;/strong&gt;.  &lt;/p&gt;




&lt;h2&gt;
  
  
  6️⃣ Independence from the Database
&lt;/h2&gt;

&lt;p&gt;The correlation engine:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does not query PostgreSQL
&lt;/li&gt;
&lt;li&gt;Does not call LLMs
&lt;/li&gt;
&lt;li&gt;Does not use vector DBs
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Benefits:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Testability with fixtures
&lt;/li&gt;
&lt;li&gt;Predictability
&lt;/li&gt;
&lt;li&gt;Separation of concerns
&lt;/li&gt;
&lt;li&gt;Flexibility for future integration
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7️⃣ Testing the Engine
&lt;/h2&gt;

&lt;p&gt;Coverage included:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Temporal correlation
&lt;/li&gt;
&lt;li&gt;Error-signature matching
&lt;/li&gt;
&lt;li&gt;Severity weighting
&lt;/li&gt;
&lt;li&gt;Service correlation
&lt;/li&gt;
&lt;li&gt;Negative tests (unrelated events)
&lt;/li&gt;
&lt;li&gt;Ordering explanations
&lt;/li&gt;
&lt;li&gt;Invalid window values
&lt;/li&gt;
&lt;li&gt;Timezone-aware timestamps
&lt;/li&gt;
&lt;li&gt;Score bounds
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚫 What It Does Not Do
&lt;/h2&gt;

&lt;p&gt;At Milestone 4, the engine does &lt;strong&gt;not&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prove root cause
&lt;/li&gt;
&lt;li&gt;Understand arbitrary error messages semantically
&lt;/li&gt;
&lt;li&gt;Use LLMs for relationships
&lt;/li&gt;
&lt;li&gt;Build full incident timelines
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Its role: &lt;strong&gt;produce deterministic correlation signals for future workflows.&lt;/strong&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Lessons Learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Normalization is prerequisite for cross-source analysis.
&lt;/li&gt;
&lt;li&gt;Explainability must be part of the output.
&lt;/li&gt;
&lt;li&gt;Deterministic ≠ infallible.
&lt;/li&gt;
&lt;li&gt;Correlation ≠ causation.
&lt;/li&gt;
&lt;li&gt;Incremental development controls complexity.
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔮 What’s Next?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Milestone 5 → Incident Timeline &amp;amp; Lifecycle.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;This will organize correlated events into timelines and introduce lifecycle behavior. Later milestones will add:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval-augmented generation (Qdrant)
&lt;/li&gt;
&lt;li&gt;Structured diagnosis (Ollama)
&lt;/li&gt;
&lt;li&gt;Frontend for investigation
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;Milestone 4 delivered a deterministic correlation engine that evaluates temporal proximity, service identity, error signatures, severity, and ordering.  &lt;/p&gt;

&lt;p&gt;It produces structured scores and explanations, distinguishing &lt;strong&gt;possible relationships from proven causation.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;IncidentCopilot is being built milestone by milestone, with &lt;strong&gt;local-first operation, testability, and transparency&lt;/strong&gt; as core priorities.  &lt;/p&gt;




&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://www.github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;br&gt;&lt;br&gt;
➡️ &lt;strong&gt;Next:&lt;/strong&gt; Milestone 5 — Incident Timeline &amp;amp; Lifecycle  &lt;/p&gt;

</description>
      <category>devops</category>
      <category>fastapi</category>
      <category>postgres</category>
      <category>ai</category>
    </item>
    <item>
      <title>🛠️ Building Multi-Source Log Ingestion for an AI DevOps Incident Copilot</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Sat, 10 Oct 2026 00:13:19 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-multi-source-log-ingestion-for-an-ai-devops-incident-copilot-2ffa</link>
      <guid>https://dev.to/richard_atodo/building-multi-source-log-ingestion-for-an-ai-devops-incident-copilot-2ffa</guid>
      <description>&lt;h2&gt;
  
  
  📌 Introduction
&lt;/h2&gt;

&lt;p&gt;One of the first challenges in building an incident investigation tool is getting logs from different systems into a form the application can work with consistently.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nginx&lt;/strong&gt; → access and error logs
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes&lt;/strong&gt; → events about workloads and containers
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker&lt;/strong&gt; → container output
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Applications&lt;/strong&gt; → structured/unstructured messages
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions&lt;/strong&gt; → workflow and job failures
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These sources differ in structure and terminology, but an incident investigation system needs to examine them together.  &lt;/p&gt;

&lt;p&gt;Milestone 3 of &lt;strong&gt;IncidentCopilot&lt;/strong&gt; focused on building the ingestion foundation — ensuring the application can &lt;strong&gt;accept, validate, normalize, and persist logs reliably.&lt;/strong&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  🔎 The Scope: Five Log Sources
&lt;/h2&gt;

&lt;p&gt;Supported sources:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nginx
&lt;/li&gt;
&lt;li&gt;Kubernetes
&lt;/li&gt;
&lt;li&gt;Docker
&lt;/li&gt;
&lt;li&gt;Application logs
&lt;/li&gt;
&lt;li&gt;GitHub Actions
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each source has its own parser module. Parsers produce a &lt;strong&gt;shared normalized representation&lt;/strong&gt; with fields like:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Source
&lt;/li&gt;
&lt;li&gt;Timestamp
&lt;/li&gt;
&lt;li&gt;Severity
&lt;/li&gt;
&lt;li&gt;Service
&lt;/li&gt;
&lt;li&gt;Event type
&lt;/li&gt;
&lt;li&gt;Message
&lt;/li&gt;
&lt;li&gt;Metadata
&lt;/li&gt;
&lt;li&gt;Raw message
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source-specific details remain in metadata (e.g., Nginx → HTTP status code, Kubernetes → namespace + pod info).  &lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ Ingestion API
&lt;/h2&gt;

&lt;p&gt;Endpoints:  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Endpoint&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/logs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Submit one log&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/logs/batch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Submit multiple logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/logs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List logs with pagination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/api/v1/logs/{id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retrieve a specific log&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Batch endpoint accepts &lt;strong&gt;1–100 records&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Source-specific schemas validate incoming data.
&lt;/li&gt;
&lt;li&gt;Invalid batch items → request rejected before ingestion.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ What Worked — and What Needed Fixing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Live API checks confirmed single + batch ingestion worked (&lt;code&gt;201 Created&lt;/code&gt;, &lt;code&gt;200 OK&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;But one test failed: expected empty collection → got six records.
&lt;/li&gt;
&lt;li&gt;Cause: test queried dev DB with leftover data from live checks.
&lt;/li&gt;
&lt;li&gt;Fix: &lt;strong&gt;test environment isolation.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧪 Isolating the Test Database
&lt;/h2&gt;

&lt;p&gt;Solution:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created dedicated DB → &lt;code&gt;incidentcopilot_test&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Applied Alembic migrations.
&lt;/li&gt;
&lt;li&gt;Added pytest fixture in &lt;code&gt;backend/tests/conftest.py&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Test-specific SQLAlchemy engine + session
&lt;/li&gt;
&lt;li&gt;Overrides FastAPI DB dependency
&lt;/li&gt;
&lt;li&gt;Transaction rollback after each test
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Benefits:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Environment isolation&lt;/strong&gt; → tests no longer run against dev DB.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test isolation&lt;/strong&gt; → records rolled back after each test.
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔍 Verification
&lt;/h2&gt;

&lt;p&gt;After correction:  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Verification&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;First run&lt;/td&gt;
&lt;td&gt;27 passed in 0.88s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Second run&lt;/td&gt;
&lt;td&gt;27 passed in 2.00s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alembic check&lt;/td&gt;
&lt;td&gt;No new upgrade ops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Git diff check&lt;/td&gt;
&lt;td&gt;No whitespace errors&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Suite covers API, DB connectivity, health checks, ingestion validation, batch handling, unknown IDs.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🚫 What This Milestone Does Not Do
&lt;/h2&gt;

&lt;p&gt;Milestone 3 = ingestion foundation.  &lt;/p&gt;

&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; yet:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Correlate logs into incidents
&lt;/li&gt;
&lt;li&gt;Build investigation timelines
&lt;/li&gt;
&lt;li&gt;Query vector DB
&lt;/li&gt;
&lt;li&gt;Generate AI diagnoses
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📚 Lessons Learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Different sources need different validation, but a common representation.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live API checks ≠ automated tests.&lt;/strong&gt; Controlled setup matters.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test isolation improves engineering quality.&lt;/strong&gt; Dedicated test DB + rollback fixtures made the suite reliable.
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔮 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Next milestone → &lt;strong&gt;log normalization + correlation.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;That work will connect related events into incident context. AI diagnosis and retrieval layers will come later.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;Milestone 3 delivered:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-source ingestion workflow
&lt;/li&gt;
&lt;li&gt;Source-specific parsers + validation
&lt;/li&gt;
&lt;li&gt;Normalization with raw evidence preserved
&lt;/li&gt;
&lt;li&gt;Single + batch ingestion endpoints
&lt;/li&gt;
&lt;li&gt;PostgreSQL persistence
&lt;/li&gt;
&lt;li&gt;Reliable test isolation (27 passing tests)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This milestone wasn’t just about accepting logs — it was about making the foundation &lt;strong&gt;testable enough to trust&lt;/strong&gt; as the project grows.  &lt;/p&gt;




&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://www.github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;br&gt;&lt;br&gt;
➡️ &lt;strong&gt;Next:&lt;/strong&gt; Milestone 4 — Normalization &amp;amp; Correlation Engine  &lt;/p&gt;

</description>
      <category>fastapi</category>
      <category>postgressql</category>
      <category>ai</category>
      <category>devops</category>
    </item>
    <item>
      <title>🛠️ Building the Foundation of an AI DevOps Incident Copilot: FastAPI, PostgreSQL, and SQLAlchemy</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Fri, 09 Oct 2026 11:34:46 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-the-foundation-of-an-ai-devops-incident-copilot-fastapi-postgresql-and-sqlalchemy-445i</link>
      <guid>https://dev.to/richard_atodo/building-the-foundation-of-an-ai-devops-incident-copilot-fastapi-postgresql-and-sqlalchemy-445i</guid>
      <description>&lt;h2&gt;
  
  
  📌 Introduction
&lt;/h2&gt;

&lt;p&gt;When building an AI-powered DevOps incident investigation system, it’s tempting to start with the flashy features: log analysis, AI-generated root-cause explanations, and automated troubleshooting.  &lt;/p&gt;

&lt;p&gt;But those depend on something more fundamental: &lt;strong&gt;a reliable backend, a structured data model, and persistent storage.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;As part of my &lt;strong&gt;IncidentCopilot&lt;/strong&gt; project, &lt;strong&gt;Milestone 2&lt;/strong&gt; focused on establishing that foundation using &lt;strong&gt;FastAPI, PostgreSQL, SQLAlchemy, and Alembic.&lt;/strong&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 Project Overview
&lt;/h2&gt;

&lt;p&gt;IncidentCopilot is an open-source project designed to help developers and DevOps engineers investigate incidents more efficiently.  &lt;/p&gt;

&lt;p&gt;Planned features include:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log ingestion
&lt;/li&gt;
&lt;li&gt;Incident correlation
&lt;/li&gt;
&lt;li&gt;Investigation timelines
&lt;/li&gt;
&lt;li&gt;Evidence retrieval
&lt;/li&gt;
&lt;li&gt;AI-assisted diagnosis
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Principle: &lt;strong&gt;deterministic logic and reliable storage first, AI later.&lt;/strong&gt;  &lt;/p&gt;




&lt;h2&gt;
  
  
  1️⃣ Integrating PostgreSQL
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Added &lt;strong&gt;PostgreSQL 16&lt;/strong&gt; to Docker Compose.
&lt;/li&gt;
&lt;li&gt;Configured persistent storage with a named volume.
&lt;/li&gt;
&lt;li&gt;Health checks via &lt;code&gt;pg_isready&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Backend waits for DB readiness before starting.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚠️ Key detail:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host dev → &lt;code&gt;localhost&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Container dev → &lt;code&gt;postgres&lt;/code&gt; (Compose service name)
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2️⃣ Setting up SQLAlchemy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduced &lt;strong&gt;SQLAlchemy&lt;/strong&gt; for DB access.
&lt;/li&gt;
&lt;li&gt;Shared engine + session factory.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;get_db&lt;/code&gt; dependency ensures sessions close after requests.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3️⃣ Creating Domain Models
&lt;/h2&gt;

&lt;p&gt;Six initial models:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Incident&lt;/strong&gt; → title, severity, status, timestamps
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log&lt;/strong&gt; → source, timestamp, severity, service, event type, message, metadata (JSONB)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IncidentLog&lt;/strong&gt; → connects incidents ↔ logs, includes relevance scoring
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diagnosis&lt;/strong&gt; → summary, root cause, confidence, category, raw response (JSONB)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evidence&lt;/strong&gt; → links diagnosis ↔ logs, with reasoning
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;InvestigationStep&lt;/strong&gt; → description, status, position
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4️⃣ Managing Schema with Alembic
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Added &lt;strong&gt;Alembic&lt;/strong&gt; for migrations.
&lt;/li&gt;
&lt;li&gt;Initial migration created tables + relationships.
&lt;/li&gt;
&lt;li&gt;Verified schema alignment with:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;alembic check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No new upgrade operations detected.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5️⃣ Adding API Endpoints
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Endpoint&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /health&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Confirms app health&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /ready&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks DB connectivity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /api/v1/incidents&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Lists incidents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /api/v1/logs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Lists logs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Example readiness response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ready"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  6️⃣ Testing the Foundation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Tests for health, readiness, DB connectivity, model registration, empty endpoints.
&lt;/li&gt;
&lt;li&gt;Result:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6 passed, 1 warning in 2.33s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Verified Docker Compose config + DB migration state.
&lt;/li&gt;
&lt;li&gt;Backend resolved &lt;code&gt;postgres&lt;/code&gt; hostname correctly.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7️⃣ Lessons Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clear domain model matters&lt;/strong&gt; → incidents, logs, evidence, diagnoses, steps each have distinct roles.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep config outside code&lt;/strong&gt; → easier portability.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use migrations early&lt;/strong&gt; → reproducible schema changes.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Health ≠ readiness&lt;/strong&gt; → DB connectivity matters.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build incrementally&lt;/strong&gt; → don’t rush correlation or AI.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔮 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Milestone 3 → &lt;strong&gt;multi-source log ingestion.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Future milestones:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Normalization
&lt;/li&gt;
&lt;li&gt;Incident correlation
&lt;/li&gt;
&lt;li&gt;Investigation timelines
&lt;/li&gt;
&lt;li&gt;Retrieval-augmented generation (RAG)
&lt;/li&gt;
&lt;li&gt;AI-assisted diagnosis
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;Milestone 2 wasn’t about flashy AI. It was about &lt;strong&gt;laying a dependable foundation.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;By integrating PostgreSQL, SQLAlchemy, Alembic, structured domain models, versioned API endpoints, and automated tests, IncidentCopilot now has the backend infrastructure to grow.  &lt;/p&gt;

&lt;p&gt;Next challenge: &lt;strong&gt;make the foundation useful by ingesting operational logs.&lt;/strong&gt;  &lt;/p&gt;




&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://www.github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;br&gt;&lt;br&gt;
➡️ &lt;strong&gt;Next:&lt;/strong&gt; Milestone 3 — Multi-source Log Ingestion  &lt;/p&gt;

</description>
      <category>postgressql</category>
      <category>fastapi</category>
      <category>docker</category>
      <category>sqlalchemy</category>
    </item>
    <item>
      <title>Building IncidentCopilot: Establishing a Local-First AI DevOps Development Foundation</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Thu, 01 Oct 2026 21:53:42 +0000</pubDate>
      <link>https://dev.to/richard_atodo/building-incidentcopilot-establishing-a-local-first-ai-devops-development-foundation-2330</link>
      <guid>https://dev.to/richard_atodo/building-incidentcopilot-establishing-a-local-first-ai-devops-development-foundation-2330</guid>
      <description>&lt;p&gt;&lt;strong&gt;Project:&lt;/strong&gt; IncidentCopilot — AI DevOps Incident Investigation&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Milestone:&lt;/strong&gt; 1 — Repository &amp;amp; Local Development Foundation&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Status:&lt;/strong&gt; ✅ Completed  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp8o5l3yozgp7z2cch7xw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp8o5l3yozgp7z2cch7xw.png" alt="IncidentCopilot Homepage" width="799" height="361"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 Why Start With the Foundation?
&lt;/h2&gt;

&lt;p&gt;When building an AI-powered DevOps system, it’s tempting to jump straight into the LLM.  &lt;/p&gt;

&lt;p&gt;For IncidentCopilot, I deliberately chose not to.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Evidence first. AI second. Human in the loop.&lt;/strong&gt;  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The AI should reason over verified evidence, not replace deterministic systems like parsing, normalization, persistence, or correlation.  &lt;/p&gt;

&lt;p&gt;So Milestone 1 focused on:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repository structure
&lt;/li&gt;
&lt;li&gt;Local dev environment
&lt;/li&gt;
&lt;li&gt;Backend &amp;amp; frontend foundations
&lt;/li&gt;
&lt;li&gt;Config management
&lt;/li&gt;
&lt;li&gt;Testing setup
&lt;/li&gt;
&lt;li&gt;Docker &amp;amp; Compose
&lt;/li&gt;
&lt;li&gt;Documentation &amp;amp; reproducibility
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🖥️ Local-First Decision
&lt;/h2&gt;

&lt;p&gt;IncidentCopilot is intentionally &lt;strong&gt;local-first&lt;/strong&gt;. No reliance on:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS / Azure / GCP
&lt;/li&gt;
&lt;li&gt;Paid APIs
&lt;/li&gt;
&lt;li&gt;Proprietary SaaS infrastructure
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead, the stack runs via &lt;strong&gt;Docker Compose&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI
&lt;/li&gt;
&lt;li&gt;PostgreSQL
&lt;/li&gt;
&lt;li&gt;Qdrant
&lt;/li&gt;
&lt;li&gt;Ollama
&lt;/li&gt;
&lt;li&gt;React
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📂 Repository Structure
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;incidentcopilot/
├── backend/
├── frontend/
├── runbooks/
├── test-data/
├── evaluation/
├── docker-compose.yml
├── .env.example
├── README.md
└── Makefile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Backend packages were defined but left intentionally empty — establishing architectural direction without premature implementation.  &lt;/p&gt;


&lt;h2&gt;
  
  
  ⚙️ Backend Foundation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvi2g6x45tld94clazmx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvi2g6x45tld94clazmx5.png" alt="Fastapi UI" width="800" height="363"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI&lt;/strong&gt; app with two endpoints:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /health → {"status": "ok"}
GET /ready → {"status": "ready"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Config management&lt;/strong&gt; via &lt;code&gt;pydantic-settings&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing&lt;/strong&gt; with Pytest + FastAPI’s &lt;code&gt;TestClient&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerized backend&lt;/strong&gt; (minimal container, no DB/AI yet)
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🎨 Frontend Foundation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React + TypeScript + Vite + Tailwind CSS + Lucide icons
&lt;/li&gt;
&lt;li&gt;Minimal shell:
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;IncidentCopilot — AI DevOps Incident Investigation&lt;/em&gt;  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Cleaned unused Vite starter files
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerized frontend&lt;/strong&gt; with Node-based build image
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🛠️ Real Problems &amp;amp; Fixes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js mismatch:&lt;/strong&gt; upgraded from v20 → v24 for Vite
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker Desktop:&lt;/strong&gt; CLI installed but engine not running — fixed by starting Docker Desktop
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windows &lt;code&gt;make&lt;/code&gt;:&lt;/strong&gt; used &lt;code&gt;mingw32-make&lt;/code&gt; instead of GNU &lt;code&gt;make&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git hygiene:&lt;/strong&gt; fixed invalid UTF-8 README + refined &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  ✅ Verification
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Git hygiene → clean
&lt;/li&gt;
&lt;li&gt;Backend tests → 1 passed
&lt;/li&gt;
&lt;li&gt;Frontend lint → 0 errors
&lt;/li&gt;
&lt;li&gt;Frontend build → ✓ built
&lt;/li&gt;
&lt;li&gt;Docker Compose config → valid
&lt;/li&gt;
&lt;li&gt;Backend &amp;amp; frontend containers → running locally
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧩 What We Didn’t Build (Yet)
&lt;/h2&gt;

&lt;p&gt;Milestone 1 deliberately excluded:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PostgreSQL models
&lt;/li&gt;
&lt;li&gt;Log ingestion APIs
&lt;/li&gt;
&lt;li&gt;Parsers (Nginx, Kubernetes, Docker, GitHub Actions)
&lt;/li&gt;
&lt;li&gt;Normalization &amp;amp; correlation
&lt;/li&gt;
&lt;li&gt;Qdrant + RAG integration
&lt;/li&gt;
&lt;li&gt;Ollama integration
&lt;/li&gt;
&lt;li&gt;Structured AI diagnosis
&lt;/li&gt;
&lt;li&gt;Full incident dashboard
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These belong to future milestones.  &lt;/p&gt;


&lt;h2&gt;
  
  
  🏗️ Architecture Principle
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reliable evidence
       ↓
Deterministic analysis
       ↓
AI reasoning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The LLM will sit &lt;strong&gt;after&lt;/strong&gt; the deterministic evidence pipeline.  &lt;/p&gt;


&lt;h2&gt;
  
  
  📌 Key Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Foundation work = real development
&lt;/li&gt;
&lt;li&gt;Verification &amp;gt; assumptions
&lt;/li&gt;
&lt;li&gt;Starter templates should be questioned
&lt;/li&gt;
&lt;li&gt;Local-first changes dev strategy
&lt;/li&gt;
&lt;li&gt;AI shouldn’t be the first thing we build
&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  🔮 What’s Next?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Milestone 2 — FastAPI Foundation + PostgreSQL&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Moving toward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FastAPI
   ↓
Services
   ↓
PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🏁 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;IncidentCopilot is still at the beginning. No AI diagnosis yet. No RAG. No ingestion pipeline.  &lt;/p&gt;

&lt;p&gt;And that’s okay.  &lt;/p&gt;

&lt;p&gt;Milestone 1 established the engineering environment needed to build those capabilities correctly.  &lt;/p&gt;

&lt;p&gt;The project now has:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Structured monorepo
&lt;/li&gt;
&lt;li&gt;FastAPI + React/TypeScript
&lt;/li&gt;
&lt;li&gt;Tailwind CSS
&lt;/li&gt;
&lt;li&gt;Config management
&lt;/li&gt;
&lt;li&gt;Testing
&lt;/li&gt;
&lt;li&gt;Docker + Compose
&lt;/li&gt;
&lt;li&gt;Verified local workflow
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most importantly:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Build the evidence pipeline first. Let AI reason over verified evidence later.&lt;/strong&gt;  &lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://www.github.com/richardatodo/incidentcopilot" rel="noopener noreferrer"&gt;https://www.github.com/richardatodo/incidentcopilot&lt;/a&gt;&lt;br&gt;&lt;br&gt;
➡️ &lt;strong&gt;Next:&lt;/strong&gt; Milestone 2 — FastAPI + PostgreSQL  &lt;/p&gt;

</description>
      <category>ai</category>
      <category>docker</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Leveling Up: Provisioning EKS with Terraform for My DevOps Project</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Thu, 08 May 2025 08:33:36 +0000</pubDate>
      <link>https://dev.to/richard_atodo/leveling-up-provisioning-eks-with-terraform-for-my-devops-project-dpb</link>
      <guid>https://dev.to/richard_atodo/leveling-up-provisioning-eks-with-terraform-for-my-devops-project-dpb</guid>
      <description>&lt;p&gt;Following the successful containerization and CI/CD setup for my TV Shows application (as detailed in my previous post, “&lt;a href="https://dev.to/richard_atodo/from-cosmosdb-to-dynamodb-migrating-and-containerizing-a-fastapi-react-app-28dk"&gt;From CosmosDB to DynamoDB: Migrating and Containerizing a FastAPI + React App&lt;/a&gt;”), the next logical step in my “Learn to Cloud” adventure was to embrace a more robust and scalable orchestration platform: Amazon Elastic Kubernetes Service (EKS). To manage this new layer of infrastructure as code (IaC), I turned to Terraform. This post chronicles the experience, the hurdles encountered while setting up EKS with Terraform, and the solutions that paved the way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why EKS? The Push for Orchestration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While running Docker containers on a single EC2 instance with Docker Compose worked for the initial phase, the goal was always to explore true cloud-native practices. Kubernetes (and EKS as its managed AWS offering) promised:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalability: Easily scale my application pods up or down based on demand.&lt;/li&gt;
&lt;li&gt;Resilience: Automatic recovery of pods and better fault tolerance.&lt;/li&gt;
&lt;li&gt;Service Discovery &amp;amp; Load Balancing: Integrated mechanisms for inter-service communication and exposing applications.&lt;/li&gt;
&lt;li&gt;Declarative Configuration: Defining my desired application state with Kubernetes manifests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Terraform: The Tool for the Job&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Manually clicking through the AWS console to set up an EKS cluster, VPC, node groups, and all associated IAM roles and security groups is complex and error-prone. With its declarative IaC approach, Terraform was the clear choice to automate this provisioning, ensuring repeatability and version control for my infrastructure. I decided to leverage the official &lt;code&gt;terraform-aws-modules/eks/aws&lt;/code&gt; module, which significantly simplifies EKS setup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge 1: Mastering Terraform Remote Backend State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before starting on EKS, best practice dictates setting up a remote backend for Terraform state. This is crucial for collaboration and preventing state loss. I opted for S3 with DynamoDB for locking.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Stumble: I ran into a really weird issue. My initial mistake was including the resource definitions for the S3 bucket and DynamoDB table within the same Terraform configuration that was also defining the EKS cluster and using that S3 bucket as its backend.&lt;/li&gt;
&lt;li&gt;The Symptom: When I ran &lt;code&gt;terraform apply&lt;/code&gt; for my EKS cluster, it seemed to be destroying the very S3 bucket and DynamoDB table that held my Terraform state! Terraform would start creating EKS resources, then attempt to "manage" (and destroy) the S3 bucket it was actively using. This caused the apply to fail spectacularly mid-operation, as Terraform couldn't save its state to a bucket it had just deleted, or release a lock from a DynamoDB table that no longer existed. The errors were clear: &lt;code&gt;NoSuchBucket&lt;/code&gt;and &lt;code&gt;ResourceNotFoundException&lt;/code&gt; for the lock table. As you can imagine, this was causing a mess, losing my Terraform state, and leading to issues with Terraform locks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution (Initial Part): The key was strict separation.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a completely separate Terraform configuration (e.g., in a &lt;strong&gt;remote-backend&lt;/strong&gt; subdirectory) whose sole purpose is to define and create the S3 bucket (with versioning and encryption) and the DynamoDB table for state locking. This configuration uses the default local backend.&lt;/li&gt;
&lt;li&gt;Run terraform apply on this backend-only configuration, once to provision these resources.&lt;/li&gt;
&lt;li&gt;Then, in my main EKS Terraform configuration, I only included the &lt;code&gt;backend "s3" {}&lt;/code&gt; block in &lt;code&gt;providers.tf&lt;/code&gt;, pointing to the pre-existing bucket and table. The EKS configuration itself contained no &lt;code&gt;resource&lt;/code&gt; blocks for the backend components.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A Lingering Ghost (The Full Solution):&lt;/strong&gt; Even after separating the code, when I ran &lt;code&gt;terraform plan&lt;/code&gt; from the &lt;code&gt;eks-cluster&lt;/code&gt; directory, I noticed it still had plans to destroy 4 resources, which I knew were my state resources! The issue was that a previous (failed) apply had recorded those backend resources in the EKS configuration's state file. When I ran &lt;code&gt;terraform state list&lt;/code&gt;, the 4 resources on display were indeed the resources for the state. Terraform compared my current code (no backend resources defined) with the state file (backend resources were recorded) and concluded that since the code no longer defined them, they should be destroyed according to the state file it was managing. The fix was explicitly removing these resources from the EKS cluster's state file by running &lt;code&gt;terraform state rm &amp;lt;resource_name&amp;gt;&lt;/code&gt; for each of the four backend resources. After doing this, &lt;code&gt;terraform plan&lt;/code&gt; correctly showed 0 to destroy, acknowledging they are managed elsewhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge 2: VPC Configuration — To Create or To Use?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The EKS module can create a new VPC or use an existing one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initial Approach:&lt;/strong&gt; I let the module create a new VPC. This approach is often cleaner and ensures that all EKS tagging requirements are met automatically. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The “VpcLimitExceeded” Wall:&lt;/strong&gt; During one &lt;code&gt;terraform apply&lt;/code&gt;, I encountered the &lt;code&gt;VpcLimitExceeded&lt;/code&gt; error. My AWS account had reached its default limit of 5 VPCs per region. This was because Terraform created some resources, including VPCs, during my failed &lt;code&gt;terraform apply&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Solutions &amp;amp; Considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delete Unused VPCs:&lt;/strong&gt; The quickest fix was to log into the AWS console and delete old, unused VPCs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge 3: “Resource Already Exists” — Cleaning Up After Failed Runs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;EKS cluster creation is a lengthy process. If an &lt;strong&gt;apply&lt;/strong&gt; fails midway, some resources might be created while others aren't, and Terraform might not have recorded their creation in the state file if it crashed before saving, just like what happened with the VPCs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Problem:&lt;/strong&gt; On subsequent &lt;code&gt;terraform apply&lt;/code&gt; attempts, I encountered errors like &lt;code&gt;AlreadyExistsException&lt;/code&gt; for a KMS Alias (&lt;code&gt;alias/eks/ltc-eks-cluster&lt;/code&gt;) and a CloudWatch Log Group (&lt;code&gt;/aws/eks/ltc-eks-cluster/cluster&lt;/code&gt;). Terraform was trying to create these, but they already existed from a previous partial run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manual Deletion (Use with Caution):&lt;/strong&gt; For the KMS alias, since I was certain it was a remnant and not in use, I manually deleted it via the AWS console before re-running &lt;code&gt;apply&lt;/code&gt; was the option I took. This is riskier if you're unsure of the resource's origin.&lt;/p&gt;

&lt;p&gt;Ideally, Terraform modules are idempotent, but sometimes with complex, multi-step creations like EKS, partial failures can leave things in a state that requires manual intervention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Sweet Success: A Running EKS Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After navigating these hurdles, &lt;code&gt;terraform apply&lt;/code&gt; finally completed, and the &lt;code&gt;outputs.tf&lt;/code&gt; provided the command to configure &lt;code&gt;kubectl&lt;/code&gt;. Seeing &lt;code&gt;kubectl get nodes&lt;/code&gt; return the worker nodes from my new EKS cluster was a very satisfying moment!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Learnings from EKS &amp;amp; Terraform:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend State is Sacred:&lt;/strong&gt; Treat its setup carefully and keep it separate. Understand how state inconsistencies can lead to unexpected plans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understand Module Defaults &amp;amp; Requirements:&lt;/strong&gt; The EKS module is powerful but has expectations (like VPC subnet tagging for load balancers).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS Service Limits are Real:&lt;/strong&gt; Be aware of them, especially for resources like VPCs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failed Applies Need Cleanup/Import:&lt;/strong&gt; Don’t just keep re-running apply. Investigate "already exists" errors and either import the resource or safely delete it if it's an orphaned remnant.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patience:&lt;/strong&gt; EKS cluster provisioning takes time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the repository &lt;a href="https://github.com/richardatodo/ltc-devops-project" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Steps: Deploying the Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the EKS cluster provisioned by Terraform and my CI/CD pipeline pushing images to ECR, the next phase is to write the Kubernetes YAML manifests (Deployments, Services, ConfigMaps, Secrets) to deploy my React frontend and FastAPI backend onto the cluster. This will involve configuring Ingress for external access and IRSA for secure AWS service access from my backend pods. The journey to a fully orchestrated application continues!&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>terraform</category>
      <category>kubernetes</category>
      <category>eks</category>
    </item>
    <item>
      <title>From CosmosDB to DynamoDB: Migrating and Containerizing a FastAPI + React App</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Mon, 21 Apr 2025 13:19:30 +0000</pubDate>
      <link>https://dev.to/richard_atodo/from-cosmosdb-to-dynamodb-migrating-and-containerizing-a-fastapi-react-app-28dk</link>
      <guid>https://dev.to/richard_atodo/from-cosmosdb-to-dynamodb-migrating-and-containerizing-a-fastapi-react-app-28dk</guid>
      <description>&lt;p&gt;Building and deploying a full-stack application involves more than just writing code. It's a journey through infrastructure, automation, and inevitable troubleshooting. As part of the &lt;strong&gt;Learn to Cloud initiative&lt;/strong&gt;, I recently expanded on a previous &lt;strong&gt;Phase 2 Capstone Project (a Serverless Movies API)&lt;/strong&gt; to focus on applying core &lt;strong&gt;DevOps practices&lt;/strong&gt; like containerization, CI/CD, and eventually observability/monitoring. The target was a simple TV show application (a sample is available &lt;a href="https://github.com/rishabkumar7/ltc-devops-project" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The path from local development to a containerized deployment on AWS using CI/CD was filled with valuable lessons. Here's a look at the experience, the hurdles, and how I overcame them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Goal: A DevOps-Focused TV Show App
&lt;/h3&gt;

&lt;p&gt;The application idea was straightforward: a web app where users could browse TV shows and view details about their seasons and episodes. The core goal, however, was applying modern DevOps techniques using this stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; FastAPI (Python) for its speed and ease of use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; React for building the user interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; Initially Azure Cosmos DB, but migrated to AWS DynamoDB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment:&lt;/strong&gt; Docker containers running on an AWS EC2 instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automation:&lt;/strong&gt; GitHub Actions for CI/CD.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenge 1: Migrating the Backend (Cosmos DB to DynamoDB)&lt;/strong&gt;&lt;br&gt;
One of the first major tasks was switching the database. Moving from Azure Cosmos DB’s SQL API to DynamoDB required more than just changing connection strings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Different SDKs (&lt;code&gt;azure-cosmos vs. boto3&lt;/code&gt;) and fundamentally different query models (SQL-like queries vs. DynamoDB's key-value/document operations like &lt;code&gt;scan&lt;/code&gt; and &lt;code&gt;get_item&lt;/code&gt;). AWS authentication also needed handling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; I refactored the backend’s data access layer to use boto3. Listing all shows involved a scan operation (noting its potential performance impact on large tables), while fetching specific show details used the efficient get_item. For authentication, I transitioned from potential key-based access to using an IAM Role attached to the EC2 instance, which is much more secure. This involved ensuring the role had the correct DynamoDB permissions (&lt;code&gt;dynamodb:Scan&lt;/code&gt;, &lt;code&gt;dynamodb:GetItem&lt;/code&gt;, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenge 2: Containerizing the Stack&lt;/strong&gt;&lt;br&gt;
Dockerizing the FastAPI backend and the React frontend (using an Nginx server) seemed standard, but ensuring they worked together smoothly within Docker Compose required careful configuration. The multi-stage build for the React/Nginx frontend was key to keeping the final image small.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge 3: Setting Up the EC2 Environment&lt;/strong&gt;&lt;br&gt;
I chose Amazon Linux 2023 on a &lt;code&gt;t4g.medium&lt;/code&gt; instance (for that Graviton price-performance!). Getting the environment ready for Docker threw up some unexpected curveballs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Installing Docker Compose. My initial attempts (&lt;code&gt;sudo dnf install docker-compose&lt;/code&gt;) failed because the package name corresponds to the deprecated V1. Trying the correct V2 package (&lt;code&gt;sudo dnf install docker-compose-plugin&lt;/code&gt;) also failed initially!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; After some head-scratching, I realized the dnf package manager's cache was likely stale. Running &lt;code&gt;sudo dnf clean all&lt;/code&gt; before retrying the &lt;code&gt;docker-compose-plugin&lt;/code&gt; installation resolved the issue. This was a good reminder that package managers aren't infallible and sometimes need a refresh.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenge 4: “Unable to Connect” — The Dreaded Networking Hurdle&lt;/strong&gt;&lt;br&gt;
With the containers seemingly running via &lt;code&gt;docker compose up&lt;/code&gt;, I tried accessing the frontend from my browser using the EC2 instance's public IP and the mapped port (3000). Result: "Unable to connect."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; The connection wasn’t even reaching the application. This almost always points to a firewall issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; The culprit was the EC2 Security Group. It acts as a stateful firewall, and I hadn’t created an inbound rule to allow traffic on TCP port 3000 from my IP address (or &lt;code&gt;0.0.0.0/0&lt;/code&gt; for testing). Adding this rule immediately fixed the connection issue. Testing connectivity locally on the instance (&lt;code&gt;curl localhost:3000&lt;/code&gt;) also helped confirm the containers were running and mapped correctly, isolating the problem to the external firewall (the Security Group).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenge 5: Docker Compose Runtime Issues&lt;/strong&gt;&lt;br&gt;
Even after connecting, the application wasn’t fully working. &lt;code&gt;docker compose ps&lt;/code&gt; showed the frontend running, but the backend was missing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Docker Compose logs (&lt;code&gt;docker compose logs api-backend&lt;/code&gt;) revealed the backend container was failing to start because required environment variables (&lt;code&gt;AWS_REGION&lt;/code&gt;, &lt;code&gt;DYNAMODB_TABLE_NAME&lt;/code&gt;) were missing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; I had created a &lt;code&gt;.env&lt;/code&gt; file, but I had to double-check:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Was it in the same directory as &lt;code&gt;docker-compose.yml&lt;/code&gt;? (Checked with &lt;code&gt;ls -a&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Did it contain the correct variable names and values? (Checked with &lt;code&gt;cat .env&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Was the &lt;code&gt;docker-compose.yml&lt;/code&gt; correctly referencing these variables using the &lt;code&gt;${VAR}&lt;/code&gt; syntax in the &lt;code&gt;environment&lt;/code&gt; section for the backend service? Correcting a small mistake here and restarting with &lt;code&gt;docker compose down &amp;amp;&amp;amp; docker compose up -d&lt;/code&gt; brought the backend online.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Challenge 6: Automating Builds with GitHub Actions &amp;amp; AWS OIDC&lt;/strong&gt;&lt;br&gt;
Manually building and deploying gets tedious fast. Setting up a CI/CD pipeline using GitHub Actions to build images and push them to AWS ECR was the next goal. This involved securely authenticating GitHub Actions with AWS using OpenID Connect (OIDC).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; The workflow failed during the AWS authentication step with &lt;code&gt;Error: Could not assume role with OIDC: No OpenIDConnect provider found...&lt;/code&gt;. Even after creating the OIDC provider in AWS IAM, further errors occurred when debugging the IAM Role's Trust Policy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; This required careful configuration in AWS IAM:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creating the OIDC Provider:&lt;/strong&gt; Explicitly adding &lt;code&gt;token.actions.githubusercontent.com&lt;/code&gt; as an identity provider in IAM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuring the Role Trust Policy:&lt;/strong&gt; This was tricky. The initial policy was wrong (it trusted EC2, not GitHub OIDC). The correct policy needed:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Principal&lt;/code&gt;: Set to &lt;code&gt;"Federated"&lt;/code&gt; referencing the OIDC provider's ARN.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Action&lt;/code&gt;: Set to &lt;code&gt;"sts:AssumeRoleWithWebIdentity"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Condition&lt;/code&gt;: Carefully crafting the &lt;code&gt;sub&lt;/code&gt; claim condition to match the &lt;code&gt;repo:ORG/REPO:ref...&lt;/code&gt; format, ensuring I didn't mistakenly include the &lt;code&gt;https://github.com/&lt;/code&gt; prefix. Getting the trust policy exactly right allowed the workflow to assume the role and push images to ECR successfully.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud Services Have Nuances:&lt;/strong&gt; Migrating between databases or setting up authentication requires understanding the specific service’s model (e.g., DynamoDB queries, AWS IAM roles).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Firewalls are Foundational:&lt;/strong&gt; Security Groups are often the first place to look for connectivity issues to EC2 instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Container Orchestration Needs Precision:&lt;/strong&gt; Docker Compose relies heavily on correct file paths (&lt;code&gt;.env&lt;/code&gt;, &lt;code&gt;docker-compose.yml&lt;/code&gt;), environment variable syntax, and networking between containers. Logs are essential (&lt;code&gt;docker compose logs &amp;lt;service&amp;gt;&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Package Managers Can Be Quirky:&lt;/strong&gt; Sometimes, a simple cache clean (&lt;code&gt;dnf clean all&lt;/code&gt;) is all you need. Know the difference between V1 and V2 (e.g., &lt;code&gt;docker-compose&lt;/code&gt; vs &lt;code&gt;docker compose&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Secure CI/CD Requires Careful Setup:&lt;/strong&gt; OIDC is powerful for keyless authentication but demands precise configuration of the IAM provider and role trust policies in AWS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iterative Debugging is Key:&lt;/strong&gt; Very rarely does everything work on the first try. Systematically checking logs, configurations, and documentation is crucial.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion &amp;amp; Next Steps
&lt;/h3&gt;

&lt;p&gt;This project provided a rich learning experience across backend development, cloud database migration, containerization, EC2 instance management, and CI/CD automation within the “Learn to Cloud” framework. Encountering and solving issues with package management, security groups, environment variables, and IAM policies was invaluable. The application now runs on EC2, with deployments automated via GitHub Actions pushing to ECR. See repo &lt;a href="https://github.com/richardatodo/ltc-devops-project" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This provides a solid foundation. The next exciting phase involves using &lt;strong&gt;Infrastructure as Code (IaC) with Terraform&lt;/strong&gt; to provision the AWS resources automatically. This could set the stage for deploying the application onto &lt;strong&gt;Amazon Elastic Kubernetes Service (EKS)&lt;/strong&gt; for enhanced scalability, resilience, and management, further deepening the exploration of DevOps practices on AWS.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>docker</category>
      <category>dynamodb</category>
    </item>
    <item>
      <title>Setting Up an Automated Java Build and Deployment Pipeline with AWS CodeArtifact</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Fri, 14 Mar 2025 19:44:51 +0000</pubDate>
      <link>https://dev.to/richard_atodo/setting-up-an-automated-java-build-and-deployment-pipeline-with-aws-codeartifact-2kko</link>
      <guid>https://dev.to/richard_atodo/setting-up-an-automated-java-build-and-deployment-pipeline-with-aws-codeartifact-2kko</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this guide, I will walk you through how I set up an EC2 instance to compile, package, and publish a Java-based Maven project to AWS CodeArtifact. This setup ensures a robust and reusable package management process in a cloud-native CI/CD pipeline.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Setting Up the EC2 Instance&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.1 Launching an EC2 Instance&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I started by launching an &lt;strong&gt;Amazon Linux 2023 t3.micro&lt;/strong&gt; EC2 instance with the following specifications:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AMI:&lt;/strong&gt; Amazon Linux 2023
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instance Type:&lt;/strong&gt; t3.micro
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; 8 GB (default)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Group:&lt;/strong&gt; Allowed SSH (port 22) and HTTP (port 80)
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.2 Connecting to the EC2 Instance&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After launching the instance, I connected via SSH using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; my-key.pem ec2-user@&amp;lt;EC2-Public-IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This provided direct access to the instance for software installation.  &lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: Installing Java and Maven&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Maven is required to build and manage Java projects, while Java is needed to run Maven-based applications.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2.1 Installing Java Amazon Corretto 8&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Amazon Corretto 8 is a free, production-ready distribution of OpenJDK. I installed it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dnf &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; java-1.8.0-amazon-corretto-devel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, I set environment variables to ensure Java was properly recognized:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;JAVA_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$JAVA_HOME&lt;/span&gt;/bin:&lt;span class="nv"&gt;$PATH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this change permanent, I added the paths to &lt;code&gt;~/.bashrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'export JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'export PATH=$JAVA_HOME/bin:$PATH'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I verified the installation with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;2.2 Installing Maven 3.5.2&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Maven 3.5.2 was required to build the Java web app. I downloaded and extracted it manually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://archive.apache.org/dist/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz
&lt;span class="nb"&gt;sudo tar&lt;/span&gt; &lt;span class="nt"&gt;-xzf&lt;/span&gt; apache-maven-3.5.2-bin.tar.gz &lt;span class="nt"&gt;-C&lt;/span&gt; /opt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, I added it to my system PATH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"export PATH=/opt/apache-maven-3.5.2/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I confirmed Maven was installed by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn &lt;span class="nt"&gt;-version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: Cloning and Configuring the Java Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I initialized a Git repository on my EC2 instance and connected it to my GitHub repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git remote add origin https://github.com/richardatodo/nextwork-web-project.git
git pull origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the project directory, I ensured the required dependencies were defined in &lt;code&gt;pom.xml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependencies&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;junit&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;junit&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;3.8.1&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependencies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, I built the project to verify everything was working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn compile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4: Setting Up AWS CodeArtifact&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.1 Creating a CodeArtifact Repository and Domain&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Got it! I'll update the blog post to reflect that you created the &lt;strong&gt;CodeArtifact domain and repository via the AWS Console&lt;/strong&gt; instead of using the AWS CLI.  &lt;/p&gt;

&lt;p&gt;Here’s the revised section:  &lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4: Setting Up AWS CodeArtifact&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I created the &lt;strong&gt;CodeArtifact domain&lt;/strong&gt; and &lt;strong&gt;repository&lt;/strong&gt; via the AWS Management Console:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Navigate to AWS CodeArtifact:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the &lt;strong&gt;AWS Console&lt;/strong&gt; and go to &lt;strong&gt;CodeArtifact&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a CodeArtifact Domain:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Create domain&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Enter the &lt;strong&gt;domain name&lt;/strong&gt;: &lt;code&gt;nextwork&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create domain&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a CodeArtifact Repository:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Create repository&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Enter the &lt;strong&gt;repository name&lt;/strong&gt;: &lt;code&gt;nextwork-devops-cicd&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Select the domain &lt;code&gt;nextwork&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;(Optional) Enable &lt;strong&gt;Upstream repositories&lt;/strong&gt; if needed.
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create repository&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.2 Configuring IAM Permissions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To allow EC2 to interact with CodeArtifact, I created an IAM policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact:GetAuthorizationToken"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact:GetRepositoryEndpoint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact:ReadFromRepository"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact:PublishPackageVersion"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact:PutPackageMetadata"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:GetServiceBearerToken"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"StringEquals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"sts:AWSServiceName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"codeartifact.amazonaws.com"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I attached this policy to an IAM role and associated it with my EC2 instance.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.3 Generating an Authorization Token&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To authenticate Maven with CodeArtifact, I generated a token and stored it in an environment variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;CODEARTIFACT_AUTH_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws codeartifact get-authorization-token &lt;span class="nt"&gt;--domain&lt;/span&gt; nextwork &lt;span class="nt"&gt;--query&lt;/span&gt; authorizationToken &lt;span class="nt"&gt;--output&lt;/span&gt; text&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Step 5: Configuring Maven to Use CodeArtifact&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I created a &lt;code&gt;settings.xml&lt;/code&gt; file in my project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;settings&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;servers&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;server&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;nextwork-nextwork-devops-cicd&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;username&amp;gt;&lt;/span&gt;aws&lt;span class="nt"&gt;&amp;lt;/username&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;password&amp;gt;&lt;/span&gt;${env.CODEARTIFACT_AUTH_TOKEN}&lt;span class="nt"&gt;&amp;lt;/password&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/server&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/servers&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;profiles&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;profile&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;nextwork-nextwork-devops-cicd&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;activation&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;activeByDefault&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/activeByDefault&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/activation&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;repositories&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;repository&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;nextwork-nextwork-devops-cicd&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;url&amp;gt;&lt;/span&gt;https://nextwork-617439230997.d.codeartifact.us-east-1.amazonaws.com/maven/nextwork-devops-cicd/&lt;span class="nt"&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/repository&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/repositories&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/profile&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/profiles&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/settings&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9f1y97wfwg7lopuof1r7.png" alt="Image description" width="800" height="449"&gt;
&lt;/h2&gt;

&lt;p&gt;Then, Run the Maven compile command, which uses the settings.xml file we just configured::&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn &lt;span class="nt"&gt;-s&lt;/span&gt; settings.xml compile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulahx9kqkroxapeofm9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulahx9kqkroxapeofm9s.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 6: Publishing the Package to CodeArtifact&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I updated my &lt;code&gt;pom.xml&lt;/code&gt; to include &lt;code&gt;distributionManagement&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;distributionManagement&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;repository&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;nextwork-nextwork-devops-cicd&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;url&amp;gt;&lt;/span&gt;https://nextwork-617439230997.d.codeartifact.us-east-1.amazonaws.com/maven/nextwork-devops-cicd/&lt;span class="nt"&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/repository&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/distributionManagement&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xhxi9n03r90lre5k4jv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xhxi9n03r90lre5k4jv.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;
Then, I deployed the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn &lt;span class="nt"&gt;-s&lt;/span&gt; settings.xml deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This guide covered how I set up an AWS CodeArtifact repository, configured an EC2 instance to authenticate with it, and successfully deployed a Maven package. This process forms the foundation for integrating package management into a CI/CD pipeline, ensuring secure and scalable software delivery.  &lt;/p&gt;




</description>
      <category>devops</category>
      <category>aws</category>
      <category>cicd</category>
      <category>java</category>
    </item>
    <item>
      <title>HNG Stage 2: Deploying a FastAPI Application with a CI/CD Pipeline</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Sun, 16 Feb 2025 09:23:22 +0000</pubDate>
      <link>https://dev.to/richard_atodo/hng-stage-2-deploying-a-fastapi-application-with-a-cicd-pipeline-3b5l</link>
      <guid>https://dev.to/richard_atodo/hng-stage-2-deploying-a-fastapi-application-with-a-cicd-pipeline-3b5l</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of the HNG DevOps internship, Stage 2 required deploying a FastAPI application using Docker and setting up a CI/CD pipeline via GitHub Actions. This was an exciting challenge that tested my skills in cloud infrastructure, automation, and debugging under real-world conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Requirements Overview
&lt;/h2&gt;

&lt;p&gt;The project had several key requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implement a missing endpoint for book retrieval&lt;/li&gt;
&lt;li&gt;Set up CI/CD pipelines using GitHub Actions&lt;/li&gt;
&lt;li&gt;Containerize the application using Docker&lt;/li&gt;
&lt;li&gt;Deploy and serve the application through Nginx&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Building the Book API
&lt;/h3&gt;

&lt;p&gt;The first challenge was implementing the missing endpoint to retrieve a book by ID. The solution required careful consideration of error handling and response formatting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@router.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/{book_id}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_books&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;book_id&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;JSONResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTTP_404_NOT_FOUND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;detail&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Book not found&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;book_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting Up GitHub Actions for CI/CD
&lt;/h2&gt;

&lt;p&gt;The CI/CD setup was fascinating. I used GitHub Actions to create two essential workflows:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;test.yml&lt;/code&gt; (CI Pipeline)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Test FastAPI Application&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check out repository&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Python&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-python@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.12'&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;python -m pip install --upgrade pip&lt;/span&gt;
          &lt;span class="s"&gt;pip install -r requirements.txt&lt;/span&gt;
          &lt;span class="s"&gt;pip install pytest pytest-cov&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run pytest&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;pytest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;deploy.yml&lt;/code&gt; (CD Pipeline)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy FastAPI Application&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Python&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-python@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.12'&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;python -m pip install --upgrade pip&lt;/span&gt;
          &lt;span class="s"&gt;pip install -r requirements.txt&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run tests&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pytest&lt;/span&gt;

  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Configure SSH&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;SSH_PRIVATE_KEY&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.SSH_PRIVATE_KEY }}&lt;/span&gt;
          &lt;span class="na"&gt;SSH_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.SSH_HOST }}&lt;/span&gt;
          &lt;span class="na"&gt;SSH_USERNAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.SSH_USERNAME }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;mkdir -p ~/.ssh/&lt;/span&gt;
          &lt;span class="s"&gt;echo "$SSH_PRIVATE_KEY" &amp;gt; ~/.ssh/deploy_key&lt;/span&gt;
          &lt;span class="s"&gt;chmod 600 ~/.ssh/deploy_key&lt;/span&gt;
          &lt;span class="s"&gt;ssh-keyscan -H $SSH_HOST &amp;gt;&amp;gt; ~/.ssh/known_hosts&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to AWS EC2&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;SSH_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.SSH_HOST }}&lt;/span&gt;
          &lt;span class="na"&gt;SSH_USERNAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.SSH_USERNAME }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;ssh -i ~/.ssh/deploy_key $SSH_USERNAME@$SSH_HOST &amp;lt;&amp;lt; 'ENDSSH'&lt;/span&gt;
            &lt;span class="s"&gt;# Create project directory if it doesn't exist&lt;/span&gt;
            &lt;span class="s"&gt;mkdir -p ~/fastapi-book-project&lt;/span&gt;

            &lt;span class="s"&gt;# Navigate to project directory&lt;/span&gt;
            &lt;span class="s"&gt;cd ~/fastapi-book-project || exit 1&lt;/span&gt;

            &lt;span class="s"&gt;# Check if repository exists, if not clone it&lt;/span&gt;
            &lt;span class="s"&gt;if [ ! -d .git ]; then&lt;/span&gt;
              &lt;span class="s"&gt;git clone https://github.com/${{ github.repository }}.git .&lt;/span&gt;
            &lt;span class="s"&gt;fi&lt;/span&gt;

            &lt;span class="s"&gt;# Fetch and reset to main&lt;/span&gt;
            &lt;span class="s"&gt;git fetch --all&lt;/span&gt;
            &lt;span class="s"&gt;git reset --hard origin/main&lt;/span&gt;

            &lt;span class="s"&gt;# Check if docker-compose exists&lt;/span&gt;
            &lt;span class="s"&gt;if [ ! -f docker-compose.yml ]; then&lt;/span&gt;
              &lt;span class="s"&gt;echo "docker-compose.yml not found!"&lt;/span&gt;
              &lt;span class="s"&gt;exit 1&lt;/span&gt;
            &lt;span class="s"&gt;fi&lt;/span&gt;

            &lt;span class="s"&gt;# Stop running containers&lt;/span&gt;
            &lt;span class="s"&gt;docker-compose down || true&lt;/span&gt;

            &lt;span class="s"&gt;# Build and start containers&lt;/span&gt;
            &lt;span class="s"&gt;docker-compose up -d --build&lt;/span&gt;

            &lt;span class="s"&gt;# Verify deployment&lt;/span&gt;
            &lt;span class="s"&gt;docker ps&lt;/span&gt;

            &lt;span class="s"&gt;# Check if the application is responding&lt;/span&gt;
            &lt;span class="s"&gt;sleep 10&lt;/span&gt;
            &lt;span class="s"&gt;curl -f http://localhost:8000/api/v1/books || echo "Warning: Application not responding"&lt;/span&gt;
          &lt;span class="s"&gt;ENDSSH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dockerizing the FastAPI Application
&lt;/h2&gt;

&lt;p&gt;A key part of this challenge was containerizing the FastAPI application to ensure consistent deployment. The Dockerfile used was as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.12-slim&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;docker-compose.yml&lt;/code&gt;:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.8'&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;fastapi&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;fastapi_app&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8000:8000"&lt;/span&gt;

  &lt;span class="na"&gt;nginx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx_reverse_proxy&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;./nginx.conf:/etc/nginx/conf.d/default.conf&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;80:80"&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;fastapi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring Nginx as a Reverse Proxy
&lt;/h2&gt;

&lt;p&gt;To make the application accessible on port 80, I configured Nginx as a reverse proxy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Installed Nginx:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Created a new configuration file at &lt;code&gt;/etc/nginx/sites-available/fastapi&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;   &lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="kn"&gt;proxy_pass&lt;/span&gt; &lt;span class="s"&gt;http://localhost:8000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
           &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Host&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
           &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;X-Real-IP&lt;/span&gt; &lt;span class="nv"&gt;$remote_addr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Enabled the configuration and restarted Nginx:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /etc/nginx/sites-available/fastapi /etc/nginx/sites-enabled/
   &lt;span class="nb"&gt;sudo rm&lt;/span&gt; /etc/nginx/sites-enabled/default
   &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Debugging and Fixing Issues
&lt;/h2&gt;

&lt;p&gt;During deployment, I encountered several challenges, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Port Conflict Errors&lt;/strong&gt;: Docker was already binding to port 8000. Solved by stopping previous instances with &lt;code&gt;docker stop $(docker ps -q)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Systemd Service Failure&lt;/strong&gt;: FastAPI failed due to an address bind issue. Fixed by ensuring no other processes were using port 8000.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions Deployment Failures&lt;/strong&gt;: Resolved by properly configuring SSH keys and setting up secrets in GitHub.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This experience strengthened my ability to deploy containerized applications with automation and troubleshoot real-world deployment issues. The hands-on challenge provided deep insights into CI/CD best practices, making it a valuable learning experience.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Deploying the Number Classification API Using AWS Lambda Function URL</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Wed, 05 Feb 2025 11:16:50 +0000</pubDate>
      <link>https://dev.to/richard_atodo/deploying-the-number-classification-api-using-aws-lambda-function-url-4l5f</link>
      <guid>https://dev.to/richard_atodo/deploying-the-number-classification-api-using-aws-lambda-function-url-4l5f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;After completing my Number Classification API for Stage 1 of the HNG DevOps Internship, I deployed it. The goal was to make my API publicly accessible while ensuring seamless integration with AWS Lambda. Instead of using API Gateway, I deployed the API using AWS Lambda Function URLs, which provided a simpler and more direct approach to serving HTTP requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmotcjw0qjr57rur122v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmotcjw0qjr57rur122v.png" alt="Image description" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Number Classification API?
&lt;/h2&gt;

&lt;p&gt;The Number Classification API is a FastAPI-based service that classifies numbers based on their mathematical properties. It can determine if a number is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Prime&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Armstrong&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perfect&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Odd or even&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sum of its digits&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fun facts about the number&lt;/strong&gt; (retrieved from an external API)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This API was designed to handle both positive and negative numbers, as well as floating-point inputs, which are converted to integers. see my &lt;a href="https://github.com/richardatodo/number-classification-api" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing AWS Lambda Function URL Over API Gateway
&lt;/h2&gt;

&lt;p&gt;Initially, I considered deploying my FastAPI application using API Gateway and Lambda. However, I decided to use AWS Lambda Function URLs instead for the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: Lambda Function URLs provide a built-in HTTP endpoint, reducing the need for additional API Gateway configurations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direct Invocation&lt;/strong&gt;: Function URLs allow direct access to the Lambda function without needing an API Gateway mapping.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lower Cost&lt;/strong&gt;: Since API Gateway incurs additional costs, using Lambda Function URLs helped reduce expenses.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deployment Process
&lt;/h2&gt;

&lt;p&gt;Here’s a step-by-step breakdown of how I deployed my FastAPI application on AWS Lambda:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Preparing the Deployment Package
&lt;/h3&gt;

&lt;p&gt;To deploy a FastAPI application on AWS Lambda, it must be packaged correctly. I installed the necessary dependencies and zipped the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Compress-Archive venv&lt;span class="se"&gt;\L&lt;/span&gt;ib&lt;span class="se"&gt;\s&lt;/span&gt;ite-packages&lt;span class="se"&gt;\*&lt;/span&gt; lambda.zip 
Compress-Archive .&lt;span class="se"&gt;\m&lt;/span&gt;ain.py &lt;span class="nt"&gt;-Update&lt;/span&gt; lambda.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Creating an AWS Lambda Function
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Logged into the &lt;strong&gt;AWS Lambda console&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Created a new Lambda function using &lt;strong&gt;Python 3.9+&lt;/strong&gt; as the runtime.&lt;/li&gt;
&lt;li&gt;Uploaded the &lt;code&gt;lambda.zip&lt;/code&gt; file as the function’s code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Enabling Lambda Function URL
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Navigated to the &lt;strong&gt;Function URL&lt;/strong&gt; section in the Lambda console.&lt;/li&gt;
&lt;li&gt;Enabled the &lt;strong&gt;Function URL&lt;/strong&gt; and set the authentication type to &lt;code&gt;NONE&lt;/code&gt; to allow public access.&lt;/li&gt;
&lt;li&gt;Copied the generated Function URL for testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Configuring CORS
&lt;/h3&gt;

&lt;p&gt;Since the API was designed to be publicly accessible, I enabled CORS to allow requests from any origin. This was achieved by adding the &lt;code&gt;CORSMiddleware&lt;/code&gt; in the FastAPI application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi.middleware.cors&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CORSMiddleware&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;CORSMiddleware&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;allow_origins&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;allow_credentials&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;allow_methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;allow_headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Testing the API
&lt;/h3&gt;

&lt;p&gt;To ensure everything was working correctly, I tested the deployed API using &lt;code&gt;curl&lt;/code&gt; and a web browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; GET &lt;span class="s2"&gt;"https://your-lambda-function-url/api/classify-number?number=153"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response returned valid JSON data, confirming a successful deployment!&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges Faced
&lt;/h2&gt;

&lt;p&gt;Deploying FastAPI on AWS Lambda wasn’t without its challenges. Some key issues I encountered included:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Import Errors&lt;/strong&gt;: Initially, I faced &lt;code&gt;ImportModuleError: No module named 'pydantic_core._pydantic_core'&lt;/code&gt;, which was due to package incompatibilities. Switching to an AWS-supported Python version and ensuring all dependencies were installed inside the Lambda layer resolved this issue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CORS Issues&lt;/strong&gt;: The first few API requests were blocked due to missing CORS headers. Adding &lt;code&gt;allow_origins=["*"]&lt;/code&gt; in &lt;code&gt;CORSMiddleware&lt;/code&gt; fixed this.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number Validation Errors&lt;/strong&gt;: The API initially returned &lt;code&gt;400 Bad Request&lt;/code&gt; for negative numbers and floating-point values. After refining the number validation logic, all valid numbers were correctly processed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;Deploying a FastAPI application using AWS Lambda Function URLs proved to be an efficient and cost-effective approach. Some important lessons I learned include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS Lambda is powerful for lightweight APIs&lt;/strong&gt;: It eliminates the need for managing infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function URLs simplify deployment&lt;/strong&gt;: No need for API Gateway if a simple public endpoint is required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Proper error handling is crucial&lt;/strong&gt;: Ensuring valid JSON responses helps in debugging and API usability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CORS must be configured properly&lt;/strong&gt;: Without it, web applications may fail to make requests to the API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This project was a great learning experience and a significant milestone in my cloud journey. It reinforced my understanding of AWS Lambda, FastAPI, and CORS configurations. As I progress in the HNG DevOps Internship, I look forward to tackling more complex deployments and optimizing API performance.&lt;/p&gt;

&lt;p&gt;If you’re considering deploying a FastAPI service on AWS Lambda, I highly recommend trying Lambda Function URLs for their ease of use and cost efficiency!&lt;/p&gt;




&lt;p&gt;What are your thoughts on this approach? Let’s discuss this in the comments! 🚀&lt;/p&gt;

</description>
      <category>api</category>
      <category>python</category>
      <category>aws</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Setting Up NGINX Web Server on AWS EC2: My HNG DevOps Stage 0 Experience</title>
      <dc:creator>Richard Atodo</dc:creator>
      <pubDate>Thu, 30 Jan 2025 00:17:17 +0000</pubDate>
      <link>https://dev.to/richard_atodo/setting-up-nginx-web-server-on-aws-ec2-my-hng-devops-stage-0-experience-1mme</link>
      <guid>https://dev.to/richard_atodo/setting-up-nginx-web-server-on-aws-ec2-my-hng-devops-stage-0-experience-1mme</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of the HNG DevOps internship program, I was tasked with configuring NGINX on a fresh Ubuntu server to serve a custom HTML page. This exercise tested my ability to set up a basic web server and reinforced my understanding of cloud infrastructure.  Let me share my journey with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Approach
&lt;/h2&gt;

&lt;p&gt;The task initially seemed straightforward: set up an NGINX web server on AWS to serve a custom HTML page. However, it quickly became apparent that this project would teach me valuable lessons about system administration and web server configuration. &lt;/p&gt;

&lt;p&gt;Here's how I broke down the task:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infrastructure Setup&lt;/strong&gt;&lt;br&gt;
I started by launching an &lt;strong&gt;Ubuntu-based EC2 instance&lt;/strong&gt; on AWS. The steps included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choosing an &lt;strong&gt;Ubuntu 24.04 LTS AMI&lt;/strong&gt; (Free Tier eligible).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selecting a &lt;strong&gt;t2.micro&lt;/strong&gt; instance (Free Tier eligible).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating a security group to &lt;strong&gt;allow SSH (port 22) and HTTP (port 80)&lt;/strong&gt; access from anywhere (0.0.0.0/0).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate an &lt;strong&gt;SSH key pair&lt;/strong&gt; to connect to my instance securely.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Connecting to the Instance and NGINX Installation and Configuration&lt;/strong&gt;&lt;br&gt;
After launching the EC2 instance, I used SSH to connect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 400 your-key-pair.pem
ssh -i your-key-pair.pem ubuntu@your-instance-public-ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, I updated the system and installed and configured NGINX:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Update package list
sudo apt update

# Install NGINX
sudo apt install nginx -y

# Verify NGINX is running
sudo systemctl status nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2anpf0n047g03hkdp60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2anpf0n047g03hkdp60.png" alt="Image description" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configuring the Custom HTML Page&lt;br&gt;
Next, I replaced the default index.html file with my custom page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo tee /var/www/html/index.html &amp;lt;&amp;lt; EOF
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;DevOps Stage 0&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f0f2f5;
        }
        .message {
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="message"&amp;gt;
        &amp;lt;h1&amp;gt;Welcome to DevOps Stage 0 - [Your Name]/[SlackName]&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffffxykbyjguidipmhg9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffffxykbyjguidipmhg9v.png" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing the Setup&lt;/strong&gt;&lt;br&gt;
I tested the NGINX configuration:&lt;br&gt;
&lt;code&gt;sudo nginx -t&lt;/code&gt;&lt;br&gt;
I restarted NGINX:&lt;br&gt;
&lt;code&gt;sudo systemctl restart nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I opened a web browser and entered &lt;a href="http://ec2-public-ip/" rel="noopener noreferrer"&gt;http://ec2-public-ip/&lt;/a&gt;, confirming that my custom message was displayed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Challenges and Solutions
&lt;/h2&gt;

&lt;p&gt;I encountered permission errors. Which I fixed allowing the appropriate permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Set correct ownership and permissions
sudo chown www-data:www-data /var/www/html/index.html
sudo chmod 644 /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyix6b6qwes4gigavu3ye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyix6b6qwes4gigavu3ye.png" alt="Image description" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How This Task Contributes to My Learning and Career Goals
&lt;/h2&gt;

&lt;p&gt;Completing this task reinforced my understanding of cloud infrastructure, networking, and server administration. It was an essential step in my journey toward becoming a &lt;a href="https://hng.tech/hire/devops-engineers" rel="noopener noreferrer"&gt;DevOps Engineer&lt;/a&gt;. By working hands-on with &lt;strong&gt;AWS and NGINX&lt;/strong&gt;, I improved my troubleshooting skills and deepened my knowledge of cloud-based deployments. This experience also aligns with my long-term goal of mastering cloud automation and infrastructure management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This experience gave me practical insights into server provisioning, firewall management, and web server configuration. The ability to set up a web server from scratch is a fundamental skill for &lt;a href="https://hng.tech/hire/cloud-engineers" rel="noopener noreferrer"&gt;Cloud Engineers&lt;/a&gt; and DevOps professionals. Moving forward, I plan to explore more advanced topics like load balancing, auto-scaling, and CI/CD pipelines.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>ec2</category>
      <category>hng</category>
    </item>
  </channel>
</rss>
