@@ -14,7 +14,8 @@ resource "aws_api_gateway_rest_api" "api_gateway" {
14
14
}
15
15
16
16
resource "aws_api_gateway_deployment" "api_deployment" {
17
- rest_api_id = aws_api_gateway_rest_api. api_gateway . id
17
+ rest_api_id = aws_api_gateway_rest_api. api_gateway . id
18
+ stage_description = md5 (file (" api-gateway.tf" )) # Force a new deployment when this file changes
18
19
19
20
lifecycle {
20
21
create_before_destroy = true
@@ -48,10 +49,11 @@ resource "aws_api_gateway_resource" "api_gateway_resource" {
48
49
}
49
50
50
51
resource "aws_api_gateway_method" "api_gateway_proxy_method" {
51
- rest_api_id = aws_api_gateway_rest_api. api_gateway . id
52
- resource_id = aws_api_gateway_resource. api_gateway_resource . id
53
- http_method = " ANY"
54
- authorization = " NONE"
52
+ rest_api_id = aws_api_gateway_rest_api. api_gateway . id
53
+ resource_id = aws_api_gateway_resource. api_gateway_resource . id
54
+ http_method = " ANY"
55
+ authorization = " NONE"
56
+ api_key_required = true
55
57
56
58
request_parameters = {
57
59
" method.request.path.proxy" = true
@@ -80,3 +82,25 @@ resource "aws_api_gateway_integration" "api_proxy_integration" {
80
82
type = " AWS_PROXY"
81
83
uri = aws_lambda_function. api_lambda . invoke_arn
82
84
}
85
+
86
+ #
87
+ # API gateway usage plan and key
88
+ #
89
+ resource "aws_api_gateway_usage_plan" "api_gateway_usage_plan" {
90
+ name = " FastAPIUsagePlan"
91
+
92
+ api_stages {
93
+ api_id = aws_api_gateway_rest_api. api_gateway . id
94
+ stage = aws_api_gateway_stage. api_stage . stage_name
95
+ }
96
+ }
97
+
98
+ resource "aws_api_gateway_api_key" "api_key" {
99
+ name = " FastAPI"
100
+ }
101
+
102
+ resource "aws_api_gateway_usage_plan_key" "api_gateway_usage_plan_key" {
103
+ key_id = aws_api_gateway_api_key. api_key . id
104
+ key_type = " API_KEY"
105
+ usage_plan_id = aws_api_gateway_usage_plan. api_gateway_usage_plan . id
106
+ }
0 commit comments