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
path_part="{proxy+}"# Path part that acts as a catch-all proxy for any request path.
10
10
11
-
depends_on=[ aws_api_gateway_rest_api.api ]
11
+
depends_on=[ aws_api_gateway_rest_api.api ]# Ensure the API is created before creating the resource.
12
12
}
13
13
14
14
resource"aws_api_gateway_method""proxy_method" {
15
15
rest_api_id=aws_api_gateway_rest_api.api.id
16
16
resource_id=aws_api_gateway_resource.proxy.id
17
-
http_method="ANY"
18
-
authorization="NONE"
19
-
api_key_required=false
17
+
http_method="ANY"# Handle every type of HTTP request
18
+
authorization="NONE"# No authorization required (yet)
19
+
api_key_required=false# No API key required (yet)
20
20
request_parameters={
21
21
"method.request.path.proxy"=true
22
22
}
23
+
# This configuration allows the API Gateway to serve as a proxy for my actual backend application, handling all types of HTTP requests and forwarding them to the backend.
23
24
}
24
25
26
+
// Define the OPTIONS method for the proxy resource (for CORS preflight requests)
# Define the integration between the proxy resource and the backend application. Basically, the API Gateway will forward all requests to the backend application.
# Defines how API Gateway should handle the OPTIONS method for the proxy resource. In this case, it uses a MOCK integration to generate a mock response.
# In Amazon API Gateway, an aws_api_gateway_method_response specifies the possible responses from an API Gateway, while an aws_api_gateway_integration_response maps the response from an integration to the API Gateway response.
85
+
86
+
# This resource specifies the response parameters (headers) that the integration should return. It is part of the integration setup and tells API Gateway what to include in the response when the OPTIONS method is called.
# This resource specifies the method response parameters (headers) that the method should return. It is part of the method setup and ensures that the headers specified in the integration response are actually included in the final response sent to the client.
# This effectively triggers a redeployment whenever I do `terraform apply`, even if there are no actual changes to the configuration. I need to experiment with this setting.
112
122
triggers={
113
123
redeployment ="${timestamp()}"
114
124
}
115
125
126
+
# Minimize downtime by creating the new deployment before destroying the old one. And... because I don't think AWS would let me destroy the API given that it's in use by the load balancer.
116
127
lifecycle {
117
128
create_before_destroy=true
118
129
}
119
130
}
120
131
132
+
# An API Gateway stage is a logical reference to a lifecycle state of your API (for example, dev, test, prod). Stages are used to manage and deploy different versions of your API, allowing you to test changes in a development environment before promoting them to production.
method_path="*/*"# The path and method for which these settings apply. The format is HTTP_METHOD/RESOURCE_PATH. You can use */* to apply the settings to all methods and resources.
136
148
settings {
137
-
metrics_enabled=true
138
-
logging_level="INFO"
139
-
data_trace_enabled=true
149
+
metrics_enabled=true# Enable CloudWatch metrics for the method.
150
+
logging_level="INFO"# E.g., INFO, ERROR
151
+
data_trace_enabled=true# Can generate a large volume of log data, especially for APIs with high traffic or large payloads.
# 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.
Copy file name to clipboardExpand all lines: terraform/modules/load_balancer/main.tf
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
resource"aws_lb""this" {
2
2
name="${var.environment}-interview-prep-lb"
3
-
internal=false
4
-
load_balancer_type="application"
3
+
internal=false# Set to false to create an internet-facing load balancer
4
+
load_balancer_type="application"# Other types include network and gateway
5
5
security_groups=var.security_groups
6
6
subnets=var.public_subnet_ids
7
7
8
-
enable_deletion_protection=false
9
-
enable_http2=false
10
-
enable_cross_zone_load_balancing=true
8
+
enable_deletion_protection=false# Set to true to enable accidental deletion protection
9
+
enable_http2=false# Set to true to enable HTTP/2
10
+
enable_cross_zone_load_balancing=true# Set to true to enable cross-zone load balancing. This distributes incoming requests evenly across all registered targets in all enabled Availability Zones.
0 commit comments