diff --git a/infra/api.tf b/infra/api.tf index de32b5a..e8a5b36 100644 --- a/infra/api.tf +++ b/infra/api.tf @@ -61,6 +61,19 @@ resource "aws_apigatewayv2_route" "recipes_get_one" { target = "integrations/${aws_apigatewayv2_integration.recipes_get_one.id}" } +resource "aws_apigatewayv2_integration" "recipes_delete" { + api_id = aws_apigatewayv2_api.recipe_manager_api.id + integration_type = "AWS_PROXY" + payload_format_version = "2.0" + integration_uri = aws_lambda_function.recipes_delete.invoke_arn +} + +resource "aws_apigatewayv2_route" "recipes_delete" { + api_id = aws_apigatewayv2_api.recipe_manager_api.id + route_key = "DELETE /api/v1/recipes/{id}" + target = "integrations/${aws_apigatewayv2_integration.recipes_delete.id}" +} + resource "aws_apigatewayv2_integration" "plan_get" { api_id = aws_apigatewayv2_api.recipe_manager_api.id integration_type = "AWS_PROXY" diff --git a/infra/lambda.tf b/infra/lambda.tf index 58ba47d..41d609a 100644 --- a/infra/lambda.tf +++ b/infra/lambda.tf @@ -158,4 +158,32 @@ resource "aws_lambda_function" "plan_post" { resource "aws_cloudwatch_log_group" "plan_post_lambda_logs" { name = "/aws/lambda/${var.application_name}_plan_post" retention_in_days = 7 +} + +resource "aws_lambda_function" "recipes_delete" { + function_name = "${var.application_name}_recipes_delete" + filename = "../dist/lambda_function_payload.zip" + role = aws_iam_role.api_lambda_base_role.arn + handler = "backend.handlers.recipes.delete.handler" + layers = [aws_lambda_layer_version.requirements_layer.arn] + source_code_hash = data.archive_file.lambda.output_base64sha256 + runtime = "python3.12" + architectures = ["arm64"] + timeout = 5 + + environment { + variables = { + DYNAMODB_TABLE_NAME = var.dynamodb_table_name + } + } + + depends_on = [ + aws_iam_role_policy_attachment.recipe_manager_lambda_logs, + aws_cloudwatch_log_group.recipes_delete_lambda_logs, + ] +} + +resource "aws_cloudwatch_log_group" "recipes_delete_lambda_logs" { + name = "/aws/lambda/${var.application_name}_recipe_delete" + retention_in_days = 7 } \ No newline at end of file diff --git a/infra/lambda_resources.tf b/infra/lambda_resources.tf index 5f751fc..657236e 100644 --- a/infra/lambda_resources.tf +++ b/infra/lambda_resources.tf @@ -177,4 +177,15 @@ resource "aws_lambda_permission" "apigw_plan_post" { depends_on = [ aws_lambda_function.plan_post, ] +} + +resource "aws_lambda_permission" "apigw_recipes_delete" { + action = "lambda:InvokeFunction" + function_name = "${var.application_name}_recipes_delete" + principal = "apigateway.amazonaws.com" + source_arn = "${aws_apigatewayv2_api.recipe_manager_api.execution_arn}/*/*" + + depends_on = [ + aws_lambda_function.recipes_delete, + ] } \ No newline at end of file