File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed
Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 1+ output "invoke_url" {
2+ value = aws_apigatewayv2_api. http_api . api_endpoint
3+ }
Original file line number Diff line number Diff line change 1+ output "name" {
2+ value = aws_lambda_function. lambda . function_name
3+ }
4+
5+ output "arn" {
6+ value = aws_lambda_function. lambda . arn
7+ }
You can’t perform that action at this time.
0 commit comments