You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The diagram above illustrates the major parts of the application infrastructure:
126
+
The diagram above illustrates the major parts of the application infrastructure. Here are some descriptions and notes:
127
127
128
128
* **Interview Prep VPC**: "The Virtual Private Cloud (VPC) is a logically isolated network within the AWS cloud where we can launch and manage AWS resources. It provides a secure environment to group and connect related resources and services, such as EC2 instances, RDS databases, and ECS clusters. The VPC allows us to define our own IP address range, create subnets, and configure route tables and network gateways, ensuring that our infrastructure is both secure and scalable." (GitHub Copilot came up with such a great explanation here that I'm just going to use it as-is.)
129
129
* **Availability zones A and B**: `us-east-1a` and `us-east-1b`. These zones, along with their corresponding public and private subnets, enhance the app's resilience. Currently, one task each for the ECS frontend and backend is deployed, but this can be scaled to distribute tasks across both availability zones.
@@ -142,6 +142,13 @@ The diagram above illustrates the major parts of the application infrastructure:
142
142
* **RDS-hosted Postgres database instance**: The application uses an instance of Postgres hosted by the AWS Relational Database Service. It runs in the private subnets.
143
143
* **Migrate Lambda function**: This is a function run by the GitHub workflow. A workflow step packages up the migration files with the Lambda function itself and then invokes the function.
144
144
* **Route 53-hosted domains**: `dev.interviewprep.onyxdevtutorials.com` and `api.dev.interviewprep.onyxdevtutorials.com`. The DNS configuration in Route 53 connects the frontend and backend domains to the load balancer. This is achieved using alias records that point to the load balancer's DNS name and zone ID.
145
+
* **CIDR Blocks**: CIDR (Classless Inter-Domain Routing) blocks are used to define IP address ranges within the VPC.
146
+
* **VPC CIDR Block**: This is set to `10.0.0.0/16`, allowing for 65,536 possible IP addresses -- which is plenty for this project.
147
+
* **Subnet CIDR Blocks**: Each subnet gets 256 IP addresses:
148
+
* **Public Subnet A**: 10.0.1.0/24 provides 256 IP addresses.
149
+
* **Public Subnet B**: 10.0.2.0/24 provides 256 IP addresses.
150
+
* **Private Subnet A**: 10.0.3.0/24 provides 256 IP addresses.
151
+
* **Private Subnet B**: 10.0.4.0/24 provides 256 IP addresses.
145
152
146
153
## Costs
147
154
@@ -261,6 +268,16 @@ Once you're connected to the bastion host, you can directly access the database:
// "awsvpc" mode provides each task with its own elastic network interface (ENI)
8
+
// and a primary private IP address, allowing tasks to have full networking features
7
9
network_mode="awsvpc"
10
+
// Specifies that the task requires Fargate launch type
11
+
// Fargate is a serverless compute engine for containers that works with ECS
8
12
requires_compatibilities=["FARGATE"]
9
13
cpu="256"
10
14
memory="512"
11
15
execution_role_arn=var.ecs_task_execution_role
16
+
# task_role_arn is used for task-level permissions, e.g., AmazonS3ReadOnlyAccess, AmazonSSMReadOnlyAccess. It allows the ECS tasks to interact with other AWS services.
12
17
task_role_arn=var.ecs_task_role_arn
13
18
14
19
container_definitions=jsonencode([
15
20
{
16
21
name ="frontend"
17
22
image ="${var.frontend_repository_url}:latest"
23
+
# If this container stops or fails, the entire task is considered to have failed, and ECS will stop all other containers in the task.
# The init process handles reaping zombie processes, which are child processes that have completed execution but still have an entry in the process table.
49
+
# This can help prevent resource leaks and ensure that the container environment remains clean and efficient.
// "awsvpc" mode provides each task with its own elastic network interface (ENI)
59
+
// and a primary private IP address, allowing tasks to have full networking features
49
60
network_mode="awsvpc"
61
+
// Specifies that the task requires Fargate launch type
62
+
// Fargate is a serverless compute engine for containers that works with ECS
50
63
requires_compatibilities=["FARGATE"]
51
64
cpu="256"
52
65
memory="512"
53
66
execution_role_arn=var.ecs_task_execution_role
67
+
# task_role_arn is used for task-level permissions, e.g., AmazonS3ReadOnlyAccess, AmazonSSMReadOnlyAccess. It allows the ECS tasks to interact with other AWS services.
54
68
task_role_arn=var.ecs_task_role_arn
55
69
56
70
container_definitions=jsonencode([
57
71
{
58
72
name ="backend"
59
73
image ="${var.backend_repository_url}"
74
+
# If this container stops or fails, the entire task is considered to have failed, and ECS will stop all other containers in the task.
# The init process handles reaping zombie processes, which are child processes that have completed execution but still have an entry in the process table.
104
+
# This can help prevent resource leaks and ensure that the container environment remains clean and efficient.
Copy file name to clipboardExpand all lines: terraform/modules/iam/main.tf
+14-21Lines changed: 14 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
# Role used by ECS agent to perform actions on your behalf when launching and managing tasks. Common actions: Pulling images from ECR, writing logs to CloudWatch, etc.
# Role is assumed by the ECS tasks themselves. It allows the containers running within the tasks to interact with other AWS services. Common actions: reading from or writing to S3 buckets; accessing secrets from SSM Parameter Store; interacting with DynamoDB tables, etc. Here, because we don't attach any policies, the role does not grant any permissions to perform actions on AWS resources.
skip_final_snapshot=true# Because I don't need a backup before deletion.
22
+
apply_immediately=false# This parameter determines whether modifications to the RDS instance are applied immediately or during the next maintenance window.
allocation_id=aws_eip.nat_eip.id# An identifier for an Elastic IP (EIP) that has been allocated in your AWS account. Used to associate the Elastic IP with a NAT Gateway, ensuring that the NAT Gateway has a static public IP address.
21
21
subnet_id=var.public_subnet_a_id
22
22
tags={
23
23
Name ="interview-prep-nat-gw"
24
24
Environment = var.environment
25
25
}
26
26
}
27
27
28
+
# Allocate an Elastic IP address for the NAT Gateway.
28
29
resource"aws_eip""nat_eip" {
29
30
tags={
30
31
Name ="interview-prep-nat-eip"
@@ -35,7 +36,7 @@ resource "aws_eip" "nat_eip" {
35
36
resource"aws_route_table""public" {
36
37
vpc_id=aws_vpc.interview_prep_vpc.id
37
38
route {
38
-
cidr_block="0.0.0.0/0"
39
+
cidr_block="0.0.0.0/0"# Direct all outbound traffic to the internet gateway.
0 commit comments