<?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: Victor</title>
    <description>The latest articles on DEV Community by Victor (@non-existent).</description>
    <link>https://dev.to/non-existent</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2008384%2F3cece9f3-a398-4de7-8d68-a3b4985b8726.jpeg</url>
      <title>DEV Community: Victor</title>
      <link>https://dev.to/non-existent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/non-existent"/>
    <language>en</language>
    <item>
      <title>Part 1: Setting Up Initial AWS Infrastructure for the Intrusion Detection System with Terraform (Tutorial)</title>
      <dc:creator>Victor</dc:creator>
      <pubDate>Sat, 28 Dec 2024 17:54:16 +0000</pubDate>
      <link>https://dev.to/non-existent/part-1-setting-up-initial-aws-infrastructure-for-the-intrusion-detection-system-with-terraform-4g4e</link>
      <guid>https://dev.to/non-existent/part-1-setting-up-initial-aws-infrastructure-for-the-intrusion-detection-system-with-terraform-4g4e</guid>
      <description></description>
      <category>terraform</category>
      <category>aws</category>
      <category>infrastructureascode</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Deploying Containerized Applications to AWS ECS Using Terraform and CI/CD (Project Summary)</title>
      <dc:creator>Victor</dc:creator>
      <pubDate>Sun, 08 Dec 2024 08:51:51 +0000</pubDate>
      <link>https://dev.to/non-existent/deploying-containerized-applications-to-aws-ecs-using-terraform-and-cicd-project-summary-3llc</link>
      <guid>https://dev.to/non-existent/deploying-containerized-applications-to-aws-ecs-using-terraform-and-cicd-project-summary-3llc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this post, I'll summarize the provisioning of AWS resources with Terraform, the deployment of the Dockerized flask web-app to those resources and creating a CI/CD pipeline with GitHub actions.&lt;br&gt;
&lt;strong&gt;NOTE: This is a summary of the project, to access the complete step by step process for the deployment of the project, click the link below&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Link Available soon&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Architecture
&lt;/h2&gt;

&lt;p&gt;Here, the AWS services used for the project will be defined, alongside the AWS Architecture diagram&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS Architecture Diagram
&lt;/h3&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%2F6sqquurqb6sb57wsxqag.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%2F6sqquurqb6sb57wsxqag.png" alt="AWS Architecture diagram" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Terraform
&lt;/h2&gt;

&lt;p&gt;All infrastructure resources for this project were provisioned using Terraform with a modular approach. Each component, from the VPC to ECS, was defined within its respective Terraform module for clarity and reusability.&lt;br&gt;
The Terraform backend was created first, consisting of an S3 bucket for state storage and a DynamoDB table for state locking, ensuring safe concurrent operations. Then the remaining resources were provisioned next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backend Configuration
&lt;/h3&gt;

&lt;p&gt;Before provisioning the resources, I set up the Terraform backend. This is very important as it is where terraform will store the state files, and it is important this is separate from the main infrastructure. &lt;br&gt;
The following resources were deployed for the backend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S3 Bucket: Stores the Terraform state file.&lt;/li&gt;
&lt;li&gt;DynamoDB Table: Manages state locks to prevent concurrent changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures safe, versioned state management for the infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment resources
&lt;/h3&gt;

&lt;p&gt;The main Infrastructure is provisioned here.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Virtual Private Cloud (VPC) Module
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;VPC:&lt;/strong&gt; I created a VPC in the &lt;code&gt;us-east-1&lt;/code&gt; region&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Subnets:&lt;/strong&gt; Following the VPC, I made 4 subnets in two availability zones:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public Subnets: I made two public subnets in the &lt;code&gt;us-east 1a&lt;/code&gt; and &lt;code&gt;us-east 1b&lt;/code&gt; availability zones for the internet-facing Application Load Balancer (ALB) and other resources that require internet.&lt;/li&gt;
&lt;li&gt;Private Subnets: I made two private subnets in the &lt;code&gt;us-east 1a&lt;/code&gt; and &lt;code&gt;us-east 1b&lt;/code&gt; availability zones as well but this time it's for my ECS service tasks. This makes a more secure architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Internet Gateway (IGW):&lt;/strong&gt; I made the IGW to give the VPC and public subnets internet access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Route Tables:&lt;/strong&gt; I created the two route tables&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public Route-table: I made this route table to link the VPC to the Internet Gateway (IGW).&lt;/li&gt;
&lt;li&gt;Private Route-table: I made this route table to link my private subnets with VPC endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Route Table Associations:&lt;/strong&gt; I created this in order to associate my subnets to their respective route tables. i.e. Private Subnet to private route table and public subnet to public route table. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VPC Endpoints:&lt;/strong&gt; The VPC endpoints enable the ECS tasks in the private subnet to access certain resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ECR and Docker endpoints: Ensure ECS tasks can pull Docker images.&lt;/li&gt;
&lt;li&gt;CloudWatch endpoint: For secure logging.&lt;/li&gt;
&lt;li&gt;S3 gateway endpoint: Access data and configurations securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Application Load Balancer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Listener:&lt;/strong&gt; I created the listener to forward traffic to the ECS target group. listens on the port 80 (HTTP)&lt;br&gt;
&lt;strong&gt;Target Group:&lt;/strong&gt; The Target Group routes the traffic requests from the listener to exposed docker port in the ECS tasks in the private subnets.&lt;br&gt;
&lt;strong&gt;Security group&lt;/strong&gt; I created a security group for the ALB to specify what type of traffic to allow and on what port.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Elastic Container Service (ECS)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;ECS Service&lt;/strong&gt;: Here, the desired count of tasks is specified, the launch type, the subnets to be deployed in, the security groups, load balancer &amp;amp; target group, and the container port are all specified in this resource.&lt;br&gt;
&lt;strong&gt;Task Definitions:&lt;/strong&gt; Here, the task definition required by the ECS service is provisioned. The CPU, memory, execution role and container definitions are specified here.&lt;br&gt;
&lt;strong&gt;IAM service roles and execution role&lt;/strong&gt;: I created the necessary IAM service roles for the ECS service and the task execution role for the task definition.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Elastic Container Registry (ECR)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;I Created this resource to hold my docker image.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Route 53
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;I used this service for DNS configuration for the application domain, routing traffic to the ALB.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Challenges faced and solutions
&lt;/h3&gt;

&lt;p&gt;1.ECS tasks not being able to access the ALB&lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt;&lt;br&gt;
This was due to networking misconfigurations with security groups and routing. I adjusted the security group settings to ensure proper communication between the ECS tasks and the ALB, including allowing inbound HTTP traffic on &lt;code&gt;port:8080&lt;/code&gt;. Additionally, I verified that the ALB was correctly configured to route traffic to the ECS task group.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;S3 bucket state storage and DynamoDB locking conflicts
Solution:
When setting up the backend for Terraform, I encountered issues with the &lt;code&gt;terraform destroy -auto-approve&lt;/code&gt; command due to the S3 bucket and DynamoDB table. These resources were held my terraform state files and were defined in the main infrastructure, when I tried to delete also deleted my bucket and table, which contained my state files, causing issues when I want to provision the main infrastructure again.
&lt;strong&gt;Solution&lt;/strong&gt;
To resolve this, I separated the Terraforms backend and min infrastructure.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Future Improvements
&lt;/h3&gt;

&lt;p&gt;I plan to integrate unit tests in the pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for reading, check out my profile, for more Cloud and DevOps posts just like this&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Relevant Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Checkout the project on my GitHub
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&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%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VSI12" rel="noopener noreferrer"&gt;
        VSI12
      &lt;/a&gt; / &lt;a href="https://github.com/VSI12/Terraform-ECS-IDS" rel="noopener noreferrer"&gt;
        Terraform-ECS-IDS
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Deploying a Containerized Web-App to AWS ECS Using Terraform and CI/CD&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;This project focuses on deploying a dockerized Flask Classification based Intrusion Detection System (IDS) to AWS ECS (Elastic Container Service) using Terraform for provisioning AWS infrastructure and GitHub Actions for CI/CD automation
The IDS allows users to upload network traffic datasets (formatted like the NSL-KDD dataset), analyze them for potential threats, and visualize the results.&lt;/p&gt;
&lt;p&gt;The deployment architecture leverages AWS services such as Virtual Private Cloud (VPC) ECS (with Fargate), ECR (Elastic Container Registry), an Application Load Balancer (ALB), and VPC endpoints for secure network communication.
The entire infrastructure is managed as code with Terraform, ensuring consistency, scalability, and easy maintenance.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt;: Configured with public and private subnets across two availability zones for high availability and security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interget Gateway&lt;/strong&gt;: Enables communication between the VPC and the internet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC Endpoints&lt;/strong&gt;: The…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/VSI12/Terraform-ECS-IDS" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>docker</category>
      <category>githubactions</category>
      <category>terraform</category>
    </item>
    <item>
      <title>Deploying a Flask-based Intrusion Detection System to AWS ECS (Project Summary)</title>
      <dc:creator>Victor</dc:creator>
      <pubDate>Sat, 16 Nov 2024 19:22:37 +0000</pubDate>
      <link>https://dev.to/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-project-summary-1m1m</link>
      <guid>https://dev.to/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-project-summary-1m1m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this post, I'll summarize the deployment of the flask Intrusion Detection System to AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE: This is a summary of the project, to access the complete step by step process for the deployment of the project, click the link below&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/non-existent" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F2008384%2F3cece9f3-a398-4de7-8d68-a3b4985b8726.jpeg" alt="non-existent"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-with-cicd-4pgm" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Deploying a Flask-based Intrusion Detection System to AWS ECS&lt;/h2&gt;
      &lt;h3&gt;Victor ・ Nov 15&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#devops&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#python&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#aws&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#docker&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Project Architecture
&lt;/h2&gt;

&lt;p&gt;Here, the AWS services used for the project will be defined, alongside the AWS Architecture diagram&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS Architecture Diagram
&lt;/h3&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%2F1o6jxbofz1lgc2g8qsd6.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%2F1o6jxbofz1lgc2g8qsd6.png" alt="AWS Architecture diagram" width="800" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment resources
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. VPC
&lt;/h4&gt;

&lt;p&gt;I made a VPC in the us-east-1 region&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subnets:&lt;/strong&gt; Following the VPC, I made 4 subnets in two availability zones:&lt;/li&gt;
&lt;li&gt;Public Subnets: I made two public subnets in the &lt;code&gt;us-east 1a&lt;/code&gt; and &lt;code&gt;us-east 1b&lt;/code&gt; availability zones for the internet-facing Application Load Balancer (ALB) and other resources that require internet.&lt;/li&gt;
&lt;li&gt;Private Subnets: I made two private subnets in the &lt;code&gt;us-east 1a&lt;/code&gt; and &lt;code&gt;us-east 1b&lt;/code&gt; availability zones as well but this time it's for my ECS service tasks. This makes a more secure architecture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internet Gateway (IGW):&lt;/strong&gt; Attached the IGW and added it to the VPC's route table to grants the VPC internet access, as newly created VPCs don't have one attached&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. VPC Endpoints
&lt;/h4&gt;

&lt;p&gt;The VPC endpoints enable the ECS tasks in the private subnet to access certain resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ECR and Docker endpoints: Ensure ECS tasks can pull Docker images.&lt;/li&gt;
&lt;li&gt;CloudWatch endpoint: For secure logging.&lt;/li&gt;
&lt;li&gt;S3 gateway endpoint: Access data and configurations securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Application Load Balancer
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Listener: Configured to forward traffic to the ECS target group. listens on the port 80 (HTTP)&lt;/li&gt;
&lt;li&gt;Target Group: Routes requests to ECS tasks in the private subnets&lt;/li&gt;
&lt;li&gt;Distributes the incoming traffic across the ECS tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Elastic Container Registry (ECR)
&lt;/h4&gt;

&lt;p&gt;I used this service to host my docker image.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Elastic Container Service (ECS)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Task Definitions: I Defined the Docker container here and allocated the necessary resources&lt;/li&gt;
&lt;li&gt;Service: This creates the fargate tasks and scales it behind the load balancer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Route 53
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;I used this service for DNS configuration for the application domain, routing traffic to the ALB.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Challenges faced and solutions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  challenge:
&lt;/h4&gt;

&lt;p&gt;ECS tasks in private subnet could not access the docker image for ECR&lt;/p&gt;

&lt;h4&gt;
  
  
  Solutions:
&lt;/h4&gt;

&lt;p&gt;I used VPC Endpoints to enable the ECS tasks in the private subnet access the ECR repo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Future Improvements
&lt;/h3&gt;

&lt;p&gt;I plan to automate the entire deployment by creating a CI/CD pipeline with Code Pipeline and Codebuild.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for reading, check out my profile, for more Cloud and DevOps posts just like this&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Relevant Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Checkout the project on my GitHub
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&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%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VSI12" rel="noopener noreferrer"&gt;
        VSI12
      &lt;/a&gt; / &lt;a href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;
        IDS-Project
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Flask-based Intrusion Detection System web-application deployed to AWS ECS
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Deploying an Intrusion Detection System to AWS&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;This Project demonstrates how to build and containerize a flask web-application with docker and deploy it to AWS. This architecture ensures a secure, highly available, fault tolerant and scalable build by leveraging various AWS architectures.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt;: Configured with public and private subnets across two availability zones for high availability and security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interget Gateway&lt;/strong&gt;: Enables communication between the VPC and the internet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC Endpoints&lt;/strong&gt;: The VPC endpoints enable the ECS tasks in the private subnet to access certain resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Load Balancer(ALB)&lt;/strong&gt;: Configured to forward traffic to the ECS tasks, through listeners and target groups and distributes the incoming traffic across the ECS tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Registry&lt;/strong&gt;: Host the docker image&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Service(ECS)&lt;/strong&gt;: creates the ECS cluster that hosts the Fargate service tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Pipeline&lt;/strong&gt;: Creates a CI/CD pipeline using…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>docker</category>
      <category>python</category>
    </item>
    <item>
      <title>Deploying a Flask-based Intrusion Detection System to AWS ECS</title>
      <dc:creator>Victor</dc:creator>
      <pubDate>Fri, 15 Nov 2024 14:06:52 +0000</pubDate>
      <link>https://dev.to/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-with-cicd-4pgm</link>
      <guid>https://dev.to/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-with-cicd-4pgm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this post, I’ll Walk you through the process of deploying an intrusion detection system on AWS&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE: This project assumes you already have an active AWS account and configured your account credentials (access keys) to your code editor and this project will incur some costs in your console&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Project Summary&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/non-existent" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F2008384%2F3cece9f3-a398-4de7-8d68-a3b4985b8726.jpeg" alt="non-existent"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/non-existent/deploying-a-flask-based-intrusion-detection-system-to-aws-ecs-project-summary-1m1m" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Deploying a Flask-based Intrusion Detection System to AWS ECS (Project Summary)&lt;/h2&gt;
      &lt;h3&gt;Victor ・ Nov 16&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#devops&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#aws&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#docker&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#python&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


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

&lt;h4&gt;
  
  
  Objectives
&lt;/h4&gt;

&lt;p&gt;The objectives of this project is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Containerize the application with Docker &lt;/li&gt;
&lt;li&gt;Push the container image to ECR&lt;/li&gt;
&lt;li&gt;Create a VPC, two private subnets and two public subnets&lt;/li&gt;
&lt;li&gt;Create VPC endpoints for the private subnets to access ECR&lt;/li&gt;
&lt;li&gt;Deploy an Application Load Balancer and target group in the public subnets for the ECS Service&lt;/li&gt;
&lt;li&gt;Create a Task definition for the ECS service&lt;/li&gt;
&lt;li&gt;Create an ECS cluster and an ECS service with fargate launch type in the private subnets.&lt;/li&gt;
&lt;li&gt;Create a hosted zone in route 53 and point it to the ALB's DNS name&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Project Architecture
&lt;/h4&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%2Fejjibxomtmj04mfs8o2f.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%2Fejjibxomtmj04mfs8o2f.png" alt="Project Architecture" width="800" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone Repository
&lt;/h2&gt;

&lt;p&gt;The first step is to clone the project repo.&lt;br&gt;
&lt;strong&gt;You can find the project source code in my Github Repo&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&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%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VSI12" rel="noopener noreferrer"&gt;
        VSI12
      &lt;/a&gt; / &lt;a href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;
        IDS-Project
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Flask-based Intrusion Detection System web-application deployed to AWS ECS
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Deploying an Intrusion Detection System to AWS&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;This Project demonstrates how to build and containerize a flask web-application with docker and deploy it to AWS. This architecture ensures a secure, highly available, fault tolerant and scalable build by leveraging various AWS architectures.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt;: Configured with public and private subnets across two availability zones for high availability and security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interget Gateway&lt;/strong&gt;: Enables communication between the VPC and the internet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC Endpoints&lt;/strong&gt;: The VPC endpoints enable the ECS tasks in the private subnet to access certain resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Load Balancer(ALB)&lt;/strong&gt;: Configured to forward traffic to the ECS tasks, through listeners and target groups and distributes the incoming traffic across the ECS tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Registry&lt;/strong&gt;: Host the docker image&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Service(ECS)&lt;/strong&gt;: creates the ECS cluster that hosts the Fargate service tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Pipeline&lt;/strong&gt;: Creates a CI/CD pipeline using…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Run the following commands in your terminal
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/yourusername/IDS-ECS.git
cd IDS-ECS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Containerize the application with docker
&lt;/h2&gt;

&lt;p&gt;This section will show the steps involved in creating a docker image if the web app&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Dockerize The Flask Application
&lt;/h4&gt;

&lt;p&gt;Create a Dockerfile in the project directory in order to package the flask app.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.12

#set the working dir
WORKDIR /usr/src/app

#copy the requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy all the files to the container
COPY . .

#Expose the port
EXPOSE 5000

#run the app
CMD ["gunicorn","-b","0.0.0.0:5000", "app:app"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 2: Build and test Docker Image
&lt;/h4&gt;

&lt;p&gt;It is important to build and test the docker image locally to ensure that it is working as intended&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t image-name .
docker run -p 5000:5000 image-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Push Docker Image to ECR
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Step 1. Create an Elastic Container Repository (ECR)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to the AWS ECR console and create a repository and take a note of the URI (e.g., 123456789012.dkr.ecr.region.amazonaws.com/repo-name)&lt;/li&gt;
&lt;li&gt;NOTE: Enter your ECR repo and select view push commands in order to see the commands to push the image to your ECR repo. Its those commands that will be used here.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 2. Authenticate Docker to ECR
&lt;/h4&gt;

&lt;p&gt;Run the following command to authenticate Docker with ECR (replace your-region and your-account-id):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecr get-login-password --region your-region | docker login --username AWS --password-stdin your-account-id.dkr.ecr.your-region.amazonaws.com

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 3. Tag and Push the Image
&lt;/h4&gt;

&lt;p&gt;Tag your local Docker image to match the ECR repository, then push it:&lt;/p&gt;

&lt;p&gt;NOTE: Ensure it is your accounts respective region and account-id&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker tag image-name:latest your-account-id.dkr.ecr.your-region.amazonaws.com/image-name:latest
docker push your-account-id.dkr.ecr.your-region.amazonaws.com/image-name:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Your ECR repo should look just like this is the image is pushed successfully&lt;/strong&gt;&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%2F0fq7zt3uh4ydgeg3oec2.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%2F0fq7zt3uh4ydgeg3oec2.png" alt="Docker Image push" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a VPC and its Subnets
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Take a note of the Region, as this is where all the resources will be deployed&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Create a new VPC
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to the VPC console and create a new VPC&lt;/li&gt;
&lt;li&gt;Specify CIDR block (e.g. 10.0.0.0/16)&lt;/li&gt;
&lt;/ul&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%2F5pyaoyoxxwbaahnbdwwn.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%2F5pyaoyoxxwbaahnbdwwn.png" alt="VPC" width="665" height="816"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NOTE: Ensure the &lt;code&gt;Enable DNS hostnames&lt;/code&gt; setting is checked when creating the VPC&lt;/li&gt;
&lt;/ul&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%2Fiuh14kzkzd9il0se0rj5.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%2Fiuh14kzkzd9il0se0rj5.png" alt="DNS hostname" width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Create an Internet Gateway (IGW) for the VPC
&lt;/h4&gt;

&lt;p&gt;In the VPC console, select the Intergate Gateway tab and create the internet gateway. Once the IGW is created attach it to your VPC&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%2Fibw6nby7lnijtzfp0ht2.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%2Fibw6nby7lnijtzfp0ht2.png" alt="IGW" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 3: Create Subnets
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create two subnets in one availability zone (e.g. us-east-1)&lt;/li&gt;
&lt;li&gt;Create another set of two subnets in different availability zone (AZ) (e.g. us-east-2)&lt;/li&gt;
&lt;li&gt;NOTE: In each AZ, the subnets will serve as private and public subnets respectively.&lt;/li&gt;
&lt;/ul&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%2Fs3qr73n55trntg9w6lx4.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%2Fs3qr73n55trntg9w6lx4.png" alt="Image description" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: the ECS cluster will be deployed on the private subnet and the Application Load Balancer will be in the public subnet and will access the ECS cluster in the private subnet&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 4: Update the Route tables
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create route tables for the public and private subnets and associate the route tables to the public and private subnets respectively. (Ensure the VPC in use is selected for the both of them.)&lt;/li&gt;
&lt;li&gt;For the public subnets route table, add to route to direct all outbound traffic &lt;code&gt;0.0.0.0/0&lt;/code&gt; through the internet Gateway.&lt;/li&gt;
&lt;li&gt;The private subnet will not route outbound traffic for now.&lt;/li&gt;
&lt;/ul&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%2Fcmdku6xo1ra6dmufu1xq.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%2Fcmdku6xo1ra6dmufu1xq.png" alt="Route tables" width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create VPC endpoints for ECR
&lt;/h2&gt;

&lt;p&gt;This will enable the ECS cluster to have access to the Elastic Container Registry (ECR).&lt;br&gt;
NOTE: Four Endpoints will be made for S3, ECR, DOCKER and CloudWatch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;select Endpoints and click on create endpoint.&lt;/li&gt;
&lt;/ul&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%2Fyn8v0nycl0ajtashgjku.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%2Fyn8v0nycl0ajtashgjku.png" alt="endpoint" width="708" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name the endpoint and search for the ECR api endpoint under services &lt;code&gt;com.amazonaws.us-east-1.ecr.api&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select the VPC we've been using, this will bring up the subnets option where the availability zones our private subnets are in will be selected and then finally select our private subnets and the default security group.&lt;/li&gt;
&lt;/ul&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%2F1xq1e0qcnez7ho7bpo39.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%2F1xq1e0qcnez7ho7bpo39.png" alt="endpoints" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the default and leave the policy as is and then create the VPC.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*Now create the remaining Endpoints with changing the services for docker &lt;code&gt;com.amazonaws.us-east-1.ecr.dkr&lt;/code&gt;, for CloudWatch logs &lt;code&gt;com.amazonaws.us-east-1.logs&lt;/code&gt; and for S3 &lt;code&gt;com.amazonaws.us-east-1.s3&lt;/code&gt; respectively and follow everything else exactly expect for those changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NOTE: For the S3 endpoint, select the gateway. This is called the S3 Gateway Endpoint and will prompt you to connect it to your private subnet route table, which will create a route in the route table for it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Create Application Load Balancer and Target Group
&lt;/h2&gt;

&lt;p&gt;This is a very important step as its the ALB that&lt;br&gt;
will route traffic to the private ECS service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firstly, we need to create a security group for the ALB.&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the security group on the left and select create security group. give the security a name and description.&lt;/li&gt;
&lt;li&gt;Add an inbound rule on port range &lt;code&gt;80&lt;/code&gt; and source &lt;code&gt;0.0.0.0/0&lt;/code&gt; and add a second one on port range &lt;code&gt;443&lt;/code&gt; and source &lt;code&gt;0.0.0.0/24&lt;/code&gt; for HTTP and HTTPS traffic respectively&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 1: Create a Target Group
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to the EC2 console and on the left, under Load Balancing select target group.&lt;/li&gt;
&lt;li&gt;Under basic configuration select &lt;code&gt;IP addresses&lt;/code&gt; and name the Target group&lt;/li&gt;
&lt;li&gt;Leave the Protocol and port as &lt;code&gt;HTTP&lt;/code&gt;:&lt;code&gt;80&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select the VPC we are deploying the load balancer in and scroll and click next.&lt;/li&gt;
&lt;li&gt;Here remove the IP address that is there, all IP's will be automatically added. Next, specify the port which was exposed, &lt;code&gt;Port:5000&lt;/code&gt; and Create the Target group.&lt;/li&gt;
&lt;/ul&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%2F10wqswyz5skz31jjs78v.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%2F10wqswyz5skz31jjs78v.png" alt="Target Group" width="710" height="346"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Create Application Load Balancer
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;On the left of the EC2 console, select the load balancer and select create load balancer.&lt;/li&gt;
&lt;li&gt;Select Create Application Load Balancer, this will be an internet-facing load balancer. give the ALB a name.&lt;/li&gt;
&lt;li&gt;In the network mapping section select the Created VPC and the public subnets in the two availability zones.&lt;/li&gt;
&lt;li&gt;In the Listeners and Routing section, select the created target group. The ALB will listen on &lt;code&gt;port:80&lt;/code&gt; and forward to the target group.&lt;/li&gt;
&lt;li&gt;Create the ALB.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Create Task definitions
&lt;/h2&gt;

&lt;p&gt;Go to the ECS console and select task definitions. &lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Name the task definition family&lt;/li&gt;
&lt;li&gt;Leave the default infrastructure requirements as is, but you can change the vCPU and memory based on your descretion.
&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%2Fscodnuxl01gg4ahilw1o.png" alt="Task definition" width="619" height="776"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 2: For &lt;strong&gt;&lt;em&gt;Container 1&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Give a name&lt;/li&gt;
&lt;li&gt;Go to your ECR and copy the URI of the docker image we pushed in earlier sections of this project and come back to the container 1 section of the task definitions we're creating and paste it in the Image URI for the container.&lt;/li&gt;
&lt;li&gt;For the Port mappings set it to 5000, as this was the port we exposed in our docker container and give it a name.
&lt;strong&gt;NOTE: It is very important the port mappings is the same as the exposed docker port&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add environment variables&lt;br&gt;
This will be important in the CI/CD section of this project. But will be skipped for now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go ahead and skip the remaining sections and create the task definition&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Create a Fargate cluster and service
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Create security group for the ECS service&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the security group on the left and select create security group. give the security a name and description.&lt;/li&gt;
&lt;li&gt;Add an inbound rule on port range &lt;code&gt;5000&lt;/code&gt; and source will be the Application Load Balancers security group.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 1: Create Cluster
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to the clusters tab and select create cluster, this will bring you to the cluster configuration page. Name the cluster and ensure only the AWS Fargate(Serverless) is selected under the infrastructure tab and then create the cluster.&lt;/li&gt;
&lt;/ul&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%2F89ertvaamg7889m2rwex.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%2F89ertvaamg7889m2rwex.png" alt="cluster" width="639" height="781"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Create a service
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Select the created cluster and click on the create under service.&lt;/li&gt;
&lt;/ul&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%2Fhbaemky7yclxba770fb0.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%2Fhbaemky7yclxba770fb0.png" alt="service" width="655" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will lead you to a new page where you'll specify the configuration of the Fargate service.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scroll past the Environment section and move to the Deployment Configuration. Here, specify the task definition family, which will automatically select the revision as well.&lt;/li&gt;
&lt;/ul&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%2Flb8pzjwdikbftmrbq945.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%2Flb8pzjwdikbftmrbq945.png" alt="fargate" width="537" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the Desired number of Tasks to launch. One is fine for this project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scroll to the Networking tab and select the VPC that was made and then the private subnet(s)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Load balancer section, select the load balancer type as Application Load Balancer, and select use an existing load balancer. This will bring up the ALB that was created in previous sections. select it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scroll and you'll see, listener. select use an existing listener and select the port 80 listener that is there and under target group do the same, selecting the existing target group that we made.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next is Service Auto Scaling. This is optional but is a good addition to have to scale out to app based on defined metrics. Enable this and specify the minimum and maximum number of tasks you want running. Next add a scaling policy. For this project a Target tracking policy is used alongside the &lt;code&gt;ALBrequestCountPerTarget&lt;/code&gt; ECS service metric, with the target value 50, &lt;code&gt;scale-out cooldown period&lt;/code&gt; and &lt;code&gt;Scale-in cooldown period&lt;/code&gt; as 60s&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the Service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the Service is created, the desired number of tasks will be created.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Create a Hosted Zone in route 53
&lt;/h2&gt;

&lt;p&gt;If the above instructions were followed t the T, you should have a fully functioning web app, to access it go to your load balancer, copy the DNS name and paste in your browser. But that's tedious and not using best practices. Ideally, there should be a Web application firewall in front of the ALB or CloudFront, but for simplicity we will be using only Route 53.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE: This section requires you have a registered domain name either with AWS or any other provider&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Create a hosted in
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Route 53 console.&lt;/li&gt;
&lt;li&gt;On the left tab, select Hosted Zones. you should have this.&lt;/li&gt;
&lt;/ul&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%2Fowi0mi697oaz31tjaicp.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%2Fowi0mi697oaz31tjaicp.png" alt="Hosted Zone" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Create Hosted Zone&lt;/li&gt;
&lt;li&gt;Enter your domain name and give a description. Leave the type as &lt;code&gt;Public Hosted Zone&lt;/code&gt; and select create Hosted Zone.&lt;/li&gt;
&lt;/ul&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%2Fk9mlclrcxshb9xlgcmil.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%2Fk9mlclrcxshb9xlgcmil.png" alt="domain" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Add ALB DNS name to hosted zone records
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to your ALB console and copy its DNS name.&lt;/li&gt;
&lt;li&gt;Come back to the hosted zone and select create record.&lt;/li&gt;
&lt;/ul&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%2Fkpa3fiev2q70mfrpkmmx.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%2Fkpa3fiev2q70mfrpkmmx.png" alt="Image description" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The default record type that is there is the A record, which will be used.&lt;/li&gt;
&lt;li&gt;Toggle the alias switch&lt;/li&gt;
&lt;/ul&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%2Fj18ahr3kw73evp66xakl.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%2Fj18ahr3kw73evp66xakl.png" alt="Image description" width="800" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Under choose endpoint, select the &lt;code&gt;Alias to Application and Classical Load Balancer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Next, choose the region you launched your Load Balancer in. In this case its &lt;code&gt;us-east-1&lt;/code&gt;, Ensure it's your on region.&lt;/li&gt;
&lt;li&gt;Choose your load balancer from the drop-down menu.&lt;/li&gt;
&lt;li&gt;Create record.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;This assumes you have your domain name with AWS&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  CONGRATULATIONS!!
&lt;/h2&gt;

&lt;p&gt;If you followed the Steps to the T, you should have a full functioning web-app that is accessible through your domain-name. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This was a very exciting project as I worked with VPC's, private and public subnets, VPC endpoints, ECS services, ECR, Target groups, security groups and Application load Balancer as they all came together to create this web-app.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Relevant links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;IDS-Project(GitHub Repo) &lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&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%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VSI12" rel="noopener noreferrer"&gt;
        VSI12
      &lt;/a&gt; / &lt;a href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;
        IDS-Project
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Flask-based Intrusion Detection System web-application deployed to AWS ECS
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Deploying an Intrusion Detection System to AWS&lt;/h1&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Project Overview&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;This Project demonstrates how to build and containerize a flask web-application with docker and deploy it to AWS. This architecture ensures a secure, highly available, fault tolerant and scalable build by leveraging various AWS architectures.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt;: Configured with public and private subnets across two availability zones for high availability and security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interget Gateway&lt;/strong&gt;: Enables communication between the VPC and the internet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC Endpoints&lt;/strong&gt;: The VPC endpoints enable the ECS tasks in the private subnet to access certain resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Load Balancer(ALB)&lt;/strong&gt;: Configured to forward traffic to the ECS tasks, through listeners and target groups and distributes the incoming traffic across the ECS tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Registry&lt;/strong&gt;: Host the docker image&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Container Service(ECS)&lt;/strong&gt;: creates the ECS cluster that hosts the Fargate service tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Pipeline&lt;/strong&gt;: Creates a CI/CD pipeline using…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/VSI12/IDS-Project" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Connect with me
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://linkedin.com/in/victor-iliya" rel="noopener noreferrer"&gt;https://linkedin.com/in/victor-iliya&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Resources Used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=AyFiJqoulpY" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=AyFiJqoulpY&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtube.com/playlist?list=PLqoUmUbJ_zDHPwK-ZWATXiYrUXwWkLY65&amp;amp;si=yqc6s5NUlKlCaNQe" rel="noopener noreferrer"&gt;https://youtube.com/playlist?list=PLqoUmUbJ_zDHPwK-ZWATXiYrUXwWkLY65&amp;amp;si=yqc6s5NUlKlCaNQe&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devops</category>
      <category>python</category>
      <category>aws</category>
      <category>docker</category>
    </item>
    <item>
      <title>First AWS Project</title>
      <dc:creator>Victor</dc:creator>
      <pubDate>Sat, 31 Aug 2024 17:38:17 +0000</pubDate>
      <link>https://dev.to/non-existent/first-aws-project-2gfm</link>
      <guid>https://dev.to/non-existent/first-aws-project-2gfm</guid>
      <description>&lt;p&gt;I have just Created and deployed my first static website on AWS, the first of many projects. I learned how to apply the following services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S3 buckets
*AWS certificate manager
*AWS Route 53
*AWS CloudFront Distribution&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>static</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
