Overview
AWS ECS Fargate is a serverless compute engine provided by Amazon Web Services (AWS) that simplifies the deployment and management of containerized applications. It eliminates the need for managing the underlying infrastructure, allowing you to focus on application logic while AWS handles provisioning, scaling, and maintenance of compute resources.
Components Required for Running KnowHOW on ECS
Terraform Script -
1. Infrastructure
VPC (Virtual Private Cloud): A logically isolated section of the AWS cloud where resources are launched. Configure IP address ranges, subnets, and route tables.
Subnets: Subdivisions of a VPC, typically created in different Availability Zones for high availability.
Internet Gateway: Enables communication between VPC instances and the internet.
Route Table: Defines rules for directing network traffic within the VPC.
Route Table Association: Links subnets to route tables to use defined routes.
2. Platform
ECS Cluster: A logical grouping of container instances for managing containers as a single unit.
ALB (Application Load Balancer): Distributes incoming application traffic across multiple targets.
NLB (Network Load Balancer): Routes TCP/UDP traffic at the transport layer (Layer 4).
ALB Listener: Processes connection requests and forwards them to target groups.
ALB Listener Rules: Define routing based on conditions like URL paths or hostnames.
Target Group: A collection of resources serving traffic together.
Security Group: A virtual firewall controlling inbound and outbound traffic.
3. Application
ECS Task Definition: A blueprint for containers defining parameters like Docker images, CPU/memory requirements, and networking settings.
ECS Service: Maintains a specified number of running tasks based on task definitions.
CloudWatch: Monitors performance and logs metrics.
NFS (Network File System): Provides persistent storage for MongoDB data.
IAM Role & Policy: Grants permissions for ECS tasks and services to securely access AWS resources.
Step 1: Infrastructure
Navigate to the infrastructure directory:
cd ecs_fargate/1-Infrastructure
Initialize Terraform:
Apply the configuration:
terraform apply -auto-approve
Step 2: Platform
Navigate to the platform directory:
Replace your SSL certificate ARN and actual IP address in 2-Platform/variable.tf
:
Initialize and apply Terraform:
terraform init
terraform apply -auto-approve
Step 3: Application
Navigate to the application directory:
Update the terraform.tfvars
file with the desired KnowHOW version (e.g., 7.2.0
).
Initialize and apply Terraform:
terraform init
terraform apply -auto-approve
To avoid recreating existing resources, comment out the corresponding resource block in the Terraform configuration. Example:
#resource "aws_ecs_cluster" "PSKnowHOW-Cluster" {
# name = var.ecs_cluster_name
#}
Importing Existing Resources
Import existing resources into the Terraform state:
terraform import aws_vpc.example_vpc example-vpc
Using Outputs
Define outputs in output.tf
to share resource information:
output "imported_VPC_id" {
value = aws_vpc.example_vpc.id
}
Summary
Comment existing resource blocks in Terraform.
Use terraform import
to manage existing resources.
Define outputs for sharing resource details.
This approach ensures seamless integration with existing infrastructure, minimizing the risk of unintended changes.