From a73274d74c120750db40f91eb55c76ef0fbbf6e3 Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Tue, 2 Mar 2021 12:40:02 -0800 Subject: [PATCH] More terraform --- terraform/lambda.tf | 9 --------- terraform/logging.tf | 7 +++++-- terraform/tracking.tf | 23 ++++++++++++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/terraform/lambda.tf b/terraform/lambda.tf index 94a751b..c3469eb 100644 --- a/terraform/lambda.tf +++ b/terraform/lambda.tf @@ -91,12 +91,3 @@ resource "aws_iam_role_policy" "lambda_s3_bucket_readonly" { role = aws_iam_role.ipixel_parser.name policy = data.aws_iam_policy_document.s3_bucket_readonly.json } - -resource "aws_lambda_permission" "s3_bucket_invoke_function" { - function_name = aws_lambda_function.ipixel_parser.arn - action = "lambda:InvokeFunction" - - principal = "s3.amazonaws.com" - source_arn = aws_s3_bucket.ipixel_logs.arn -} - diff --git a/terraform/logging.tf b/terraform/logging.tf index 7279aa0..b3dc209 100644 --- a/terraform/logging.tf +++ b/terraform/logging.tf @@ -3,7 +3,7 @@ # ----------------------------------------------------------------------------------------------------------- # Grant the log parsing lambda access to the logs bucket -resource "aws_lambda_permission" "allow_bucket" { +resource "aws_lambda_permission" "s3_bucket_invoke_function" { statement_id = "AllowExecutionFromS3Bucket" action = "lambda:InvokeFunction" function_name = aws_lambda_function.ipixel_parser.arn @@ -22,6 +22,8 @@ resource "aws_s3_bucket_notification" "ipixel_logs" { lambda_function { lambda_function_arn = aws_lambda_function.ipixel_parser.arn events = ["s3:ObjectCreated:*"] + filter_prefix = "RAW/" + filter_suffix = ".gz" } depends_on = [aws_lambda_permission.s3_bucket_invoke_function] @@ -38,7 +40,8 @@ resource "aws_lambda_function" "ipixel_parser" { runtime = "nodejs12.x" handler = "index.handler" - timeout = 5 + timeout = "24" + memory_size = "512" reserved_concurrent_executions = 3 environment { diff --git a/terraform/tracking.tf b/terraform/tracking.tf index f501e22..fccbd94 100644 --- a/terraform/tracking.tf +++ b/terraform/tracking.tf @@ -33,8 +33,29 @@ resource "aws_s3_bucket_object" "ipixel" { resource "aws_s3_bucket" "ipixel_logs" { bucket = "${var.site}-analytics" + lifecycle_rule { + id = "logfiles" + enabled = true + + prefix = "RAW/" + + transition { + days = 30 + storage_class = "STANDARD_IA" # or "ONEZONE_IA" + } + + # transition { + # days = 30 + # storage_class = "GLACIER" + # } + + # expiration { + # days = 90 + # } + } + tags = { - Name = "Logs Storage" + Name = "iPixel Logs Storage" Site = var.site } }