Skip to content

Commit 4547b3f

Browse files
committed
fix: missing lambda permission for api gateway
1 parent 59ae8bd commit 4547b3f

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

Diff for: api_gateway.tf

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
locals {
2-
api_id = data.tfe_outputs.network.values.api_gw_gateway_api.id
2+
api_id = data.tfe_outputs.network.values.api_gw_gateway_api.id
3+
api_execution_arn = data.tfe_outputs.network.values.api_gw_gateway_api.execution_arn
4+
35
proxy_to_alb_id = data.tfe_outputs.network.values.api_gw_integration_proxy_to_alb.id
46
}
57

@@ -14,6 +16,10 @@ resource "aws_apigatewayv2_authorizer" "lambda_authorizer_client" {
1416

1517
authorizer_payload_format_version = "2.0"
1618
enable_simple_responses = true
19+
20+
authorizer_result_ttl_in_seconds = 0 # For debugging
21+
22+
authorizer_credentials_arn = data.aws_iam_role.lab_role.arn
1723
}
1824

1925
// ----- Integrations -----
@@ -27,6 +33,8 @@ resource "aws_apigatewayv2_integration" "lambda_identification_nationalid" {
2733
integration_uri = aws_lambda_function.identification_nationalid.invoke_arn
2834

2935
payload_format_version = "2.0"
36+
37+
credentials_arn = data.aws_iam_role.lab_role.arn
3038
}
3139

3240
// ----- Routes -----
@@ -58,3 +66,36 @@ resource "aws_apigatewayv2_route" "order_confirmation" {
5866
target = "integrations/${local.proxy_to_alb_id}"
5967

6068
}
69+
70+
// ----- Main -----
71+
72+
# locals {
73+
# api_gw_redeployment_trigger = sha1(join(",", tolist([
74+
# jsonencode(aws_apigatewayv2_authorizer.lambda_authorizer_client),
75+
# jsonencode(aws_apigatewayv2_integration.lambda_identification_nationalid),
76+
# jsonencode(aws_apigatewayv2_route.client_identification),
77+
# jsonencode(aws_apigatewayv2_route.order_checkout_and_listing),
78+
# jsonencode(aws_apigatewayv2_route.order_confirmation),
79+
# ])))
80+
# }
81+
82+
# resource "aws_apigatewayv2_deployment" "deploy_computing_api_gw_resources" {
83+
# api_id = local.api_id
84+
# description = "Deployment for computing-related API Gateway resources (${local.api_gw_redeployment_trigger})"
85+
86+
# triggers = {
87+
# redeployment = local.api_gw_redeployment_trigger
88+
# }
89+
90+
# lifecycle {
91+
# create_before_destroy = true
92+
# }
93+
94+
# depends_on = [
95+
# aws_apigatewayv2_authorizer.lambda_authorizer_client,
96+
# aws_apigatewayv2_integration.lambda_identification_nationalid,
97+
# aws_apigatewayv2_route.client_identification,
98+
# aws_apigatewayv2_route.order_checkout_and_listing,
99+
# aws_apigatewayv2_route.order_confirmation,
100+
# ]
101+
# }

Diff for: cloudwatch.tf

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#tfsec:ignore:aws-cloudwatch-log-group-customer-key
2+
resource "aws_cloudwatch_log_group" "api_gateway_access_log" {
3+
name = "/aws/apigateway/SOAT-TC_API_Gateway_Access_Log"
4+
retention_in_days = 30
5+
6+
tags = {
7+
Name : "SOAT-TC API GW Default Stage Access Log Cloudwatch Log Group"
8+
}
9+
}
10+
111
#tfsec:ignore:aws-cloudwatch-log-group-customer-key
212
resource "aws_cloudwatch_log_group" "lambda_authorizer_client" {
313
name = "/aws/lambda/SOAT-TC_Lambda_Authorizer_Client_Logs"

Diff for: lambda.tf

+18
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,21 @@ resource "aws_lambda_function" "authorizer_client" {
7070
log_group = aws_cloudwatch_log_group.lambda_authorizer_client.name
7171
}
7272
}
73+
74+
resource "aws_lambda_permission" "execute_lambda1_from_apigateway" {
75+
statement_id = "AllowExecutionFromAPIGateway_SOAT_TC_Lambda_Identification_NationalID"
76+
action = "lambda:InvokeFunction"
77+
function_name = aws_lambda_function.identification_nationalid.function_name
78+
principal = "apigateway.amazonaws.com"
79+
80+
source_arn = "${local.api_execution_arn}/*/*"
81+
}
82+
83+
resource "aws_lambda_permission" "execute_lambda2_from_apigateway" {
84+
statement_id = "AllowExecutionFromAPIGateway_SOAT_TC_Lambda_Authorizer_Client"
85+
action = "lambda:InvokeFunction"
86+
function_name = aws_lambda_function.authorizer_client.function_name
87+
principal = "apigateway.amazonaws.com"
88+
89+
source_arn = "${local.api_execution_arn}/*/*"
90+
}

0 commit comments

Comments
 (0)