More terraform

This commit is contained in:
Jocelyn Badgley (Twipped) 2021-03-02 12:40:02 -08:00
parent 0d29383b38
commit a73274d74c
3 changed files with 27 additions and 12 deletions

View File

@ -91,12 +91,3 @@ resource "aws_iam_role_policy" "lambda_s3_bucket_readonly" {
role = aws_iam_role.ipixel_parser.name role = aws_iam_role.ipixel_parser.name
policy = data.aws_iam_policy_document.s3_bucket_readonly.json 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
}

View File

@ -3,7 +3,7 @@
# ----------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------
# Grant the log parsing lambda access to the logs bucket # 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" statement_id = "AllowExecutionFromS3Bucket"
action = "lambda:InvokeFunction" action = "lambda:InvokeFunction"
function_name = aws_lambda_function.ipixel_parser.arn function_name = aws_lambda_function.ipixel_parser.arn
@ -22,6 +22,8 @@ resource "aws_s3_bucket_notification" "ipixel_logs" {
lambda_function { lambda_function {
lambda_function_arn = aws_lambda_function.ipixel_parser.arn lambda_function_arn = aws_lambda_function.ipixel_parser.arn
events = ["s3:ObjectCreated:*"] events = ["s3:ObjectCreated:*"]
filter_prefix = "RAW/"
filter_suffix = ".gz"
} }
depends_on = [aws_lambda_permission.s3_bucket_invoke_function] depends_on = [aws_lambda_permission.s3_bucket_invoke_function]
@ -38,7 +40,8 @@ resource "aws_lambda_function" "ipixel_parser" {
runtime = "nodejs12.x" runtime = "nodejs12.x"
handler = "index.handler" handler = "index.handler"
timeout = 5 timeout = "24"
memory_size = "512"
reserved_concurrent_executions = 3 reserved_concurrent_executions = 3
environment { environment {

View File

@ -33,8 +33,29 @@ resource "aws_s3_bucket_object" "ipixel" {
resource "aws_s3_bucket" "ipixel_logs" { resource "aws_s3_bucket" "ipixel_logs" {
bucket = "${var.site}-analytics" 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 = { tags = {
Name = "Logs Storage" Name = "iPixel Logs Storage"
Site = var.site Site = var.site
} }
} }