Skip to content

Commit 24aba16

Browse files
committed
feat: plug in api gateway
1 parent db17be8 commit 24aba16

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

infra/modules/aws/api/main.tf

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,42 @@ module "lambda_api" {
77

88
lambda_name = "api"
99
lambda_version = var.lambda_version
10-
}
10+
}
11+
12+
resource "aws_apigatewayv2_api" "http_api" {
13+
name = "${module.lambda_api.name}-http"
14+
protocol_type = "HTTP"
15+
}
16+
17+
resource "aws_apigatewayv2_integration" "lambda_proxy" {
18+
api_id = aws_apigatewayv2_api.http_api.id
19+
integration_type = "AWS_PROXY"
20+
integration_uri = module.lambda_api.arn
21+
payload_format_version = "2.0"
22+
}
23+
24+
resource "aws_apigatewayv2_route" "root" {
25+
api_id = aws_apigatewayv2_api.http_api.id
26+
route_key = "ANY /"
27+
target = "integrations/${aws_apigatewayv2_integration.lambda_proxy.id}"
28+
}
29+
30+
resource "aws_apigatewayv2_route" "proxy" {
31+
api_id = aws_apigatewayv2_api.http_api.id
32+
route_key = "ANY /{proxy+}"
33+
target = "integrations/${aws_apigatewayv2_integration.lambda_proxy.id}"
34+
}
35+
36+
resource "aws_apigatewayv2_stage" "default" {
37+
api_id = aws_apigatewayv2_api.http_api.id
38+
name = "$default"
39+
auto_deploy = true
40+
}
41+
42+
resource "aws_lambda_permission" "allow_invoke" {
43+
statement_id = "AllowAPIGatewayInvoke"
44+
action = "lambda:InvokeFunction"
45+
function_name = module.lambda_api.arn
46+
principal = "apigateway.amazonaws.com"
47+
source_arn = "${aws_apigatewayv2_api.http_api.execution_arn}/*/*" # all routes/stages
48+
}

infra/modules/aws/api/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "invoke_url" {
2+
value = aws_apigatewayv2_api.http_api.api_endpoint
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "name" {
2+
value = aws_lambda_function.lambda.function_name
3+
}
4+
5+
output "arn" {
6+
value = aws_lambda_function.lambda.arn
7+
}

0 commit comments

Comments
 (0)