-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_gw.tf
50 lines (40 loc) · 1.28 KB
/
api_gw.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* ========================================
* API Gateway
* ========================================
*/
resource "aws_apigatewayv2_api" "api_gw" {
name = "serverless_lambda_gw"
protocol_type = "HTTP"
cors_configuration {
allow_origins = ["*"]
}
}
resource "aws_apigatewayv2_stage" "api_gw" {
api_id = aws_apigatewayv2_api.api_gw.id
name = "serverless_lambda_stage"
auto_deploy = true
}
resource "aws_apigatewayv2_integration" "api_gw" {
api_id = aws_apigatewayv2_api.api_gw.id
integration_uri = aws_lambda_function.main_lambda.invoke_arn
integration_type = "AWS_PROXY"
integration_method = "POST"
}
resource "aws_apigatewayv2_route" "api_gw" {
api_id = aws_apigatewayv2_api.api_gw.id
route_key = "GET /"
target = "integrations/${aws_apigatewayv2_integration.api_gw.id}"
}
/*
* ========================================
* Permission to Call Main Lambda
* ========================================
*/
resource "aws_lambda_permission" "api_gw" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.main_lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.api_gw.execution_arn}/*/*"
}