Skip to content

Commit

Permalink
Deploy the recipes delete lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9smith committed Nov 25, 2024
1 parent 6382643 commit f66df6c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions infra/api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions infra/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions infra/lambda_resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
}

0 comments on commit f66df6c

Please sign in to comment.