Skip to content

Commit

Permalink
feat: use script files in S3 define cartographie nationale api shape
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gavanier committed Sep 7, 2023
1 parent 8755a2c commit c9083a2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 66 deletions.
66 changes: 40 additions & 26 deletions api-gateway.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
resource "aws_apigatewayv2_api" "cartographie_nationale" {
name = "${local.product_information.context.project}-${local.product_information.context.service}"
tags = local.tags
protocol_type = "HTTP"
}

resource "aws_apigatewayv2_stage" "cartographie_nationale" {
api_id = aws_apigatewayv2_api.cartographie_nationale.id
name = "v0"
tags = local.tags

name = "production"
api_id = aws_apigatewayv2_api.cartographie_nationale.id
auto_deploy = true

access_log_settings {
Expand All @@ -27,32 +29,44 @@ resource "aws_apigatewayv2_stage" "cartographie_nationale" {
}
}

#resource "aws_apigatewayv2_integration" "hello_world" {
# api_id = aws_apigatewayv2_api.cartographie_nationale.id
#
# integration_uri = aws_lambda_function.hello_world.invoke_arn
# integration_type = "AWS_PROXY"
# integration_method = "POST"
#}

#resource "aws_apigatewayv2_route" "hello_world" {
# api_id = aws_apigatewayv2_api.cartographie_nationale.id
#
# route_key = "GET /hello"
# target = "integrations/${aws_apigatewayv2_integration.hello_world.id}"
#}
resource "aws_apigatewayv2_integration" "api_integrations" {
for_each = {
for object in data.aws_s3_object.s3_objects :
object.key => object
if object.content_type == "application/zip"
}

resource "aws_cloudwatch_log_group" "api_cartographie_nationale" {
name = "/aws/api_gw/${aws_apigatewayv2_api.cartographie_nationale.name}"
api_id = aws_apigatewayv2_api.cartographie_nationale.id

integration_uri = aws_lambda_function.api_routes[each.key].invoke_arn
integration_type = "AWS_PROXY"
integration_method = "POST"
}

resource "aws_apigatewayv2_route" "api_route" {
for_each = {
for object in data.aws_s3_object.s3_objects :
object.key => object
if object.content_type == "application/zip"
}

api_id = aws_apigatewayv2_api.cartographie_nationale.id
route_key = "GET /${aws_lambda_function.api_routes[each.key].function_name}"
target = "integrations/${aws_apigatewayv2_integration.api_integrations[each.key].id}"
}

resource "aws_cloudwatch_log_group" "api_cartographie_nationale" {
name = "/aws/api_gw/${aws_apigatewayv2_api.cartographie_nationale.name}"
tags = local.tags
retention_in_days = 30
}

#resource "aws_lambda_permission" "api_cartographie_nationale" {
# statement_id = "AllowExecutionFromAPIGateway"
# action = "lambda:InvokeFunction"
# function_name = aws_lambda_function.hello_world.function_name
# principal = "apigateway.amazonaws.com"
#
# source_arn = "${aws_apigatewayv2_api.cartographie_nationale.execution_arn}/*/*"
#}
resource "aws_lambda_permission" "api_cartographie_nationale" {
for_each = aws_lambda_function.api_routes

statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = each.value.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.cartographie_nationale.execution_arn}/*/*"
}
18 changes: 0 additions & 18 deletions dist/goodbeye/goodbye.get.js

This file was deleted.

Binary file removed dist/goodbeye/goodbye.get.zip
Binary file not shown.
18 changes: 0 additions & 18 deletions dist/hello/hello.get.js

This file was deleted.

Binary file removed dist/hello/hello.get.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion lambda.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "aws_s3_objects" "s3_objects_metadata" {
bucket = aws_s3_bucket.api.id
prefix = "production/"
prefix = "v0/"
}

data "aws_s3_object" "s3_objects" {
Expand Down
11 changes: 8 additions & 3 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
output "base_url" {
description = "Base URL for API Gateway stage."
value = aws_apigatewayv2_stage.cartographie_nationale.invoke_url
output "api_host_name" {
description = "Host name for API Gateway."
value = regex("https://(.+?)/", aws_apigatewayv2_stage.cartographie_nationale.invoke_url).0
}

output "latest_stage_id" {
description = "ID for API Gateway latest stage."
value = aws_apigatewayv2_stage.cartographie_nationale.id
}

0 comments on commit c9083a2

Please sign in to comment.