Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions apps/railgunbreaker/usw2dev/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,13 @@ resource "aws_iam_policy" "rb_gha" {
]
},
{
Sid = "AllowECRGetToken"
Sid = "AllowInvokeLambda"
Effect = "Allow"
Action = [
"ecr:GetAuthorizationToken"
],
Resource = ["*"]
},
# {
# Sid = "AllowECRPush"
# Effect = "Allow"
# Action = [
# "ecr:BatchCheckLayerAvailability",
# "ecr:CompleteLayerUpload",
# "ecr:InitiateLayerUpload",
# "ecr:PutImage",
# "ecr:UploadLayerPart"
# ]
# Resource = [aws_ecr_repository.lambda_container_repo.arn]
# }
"lambda:InvokeFunction"
]
Resource = [aws_lambda_function.pexels_image_scraper.arn]
}
]
})

Expand Down
38 changes: 38 additions & 0 deletions apps/railgunbreaker/usw2dev/lambda.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "aws_lambda_function" "pexels_image_scraper" {
function_name = "${var.project_name}-pexels-image-scraper"
role = aws_iam_role.pexels_image_scraper_lambda_exec.arn
package_type = "Image"
image_uri = "${data.terraform_remote_state.portfolio_website.outputs.lambda_ecr_repository_url}:latest"

memory_size = 1024
timeout = 60

architectures = ["x86_64"]

environment {
variables = {
PEXELS_FEATURED_UPLOADS_URL = var.pexels_url
}
}
}

# EventBridge rule to trigger lambda every 3 days
resource "aws_cloudwatch_event_rule" "pexels_scraper_periodic" {
name = "${var.project_name}-pexels-scraper-periodic-trigger"
description = "Trigger Pexels image scraper lambda every 3 days"
schedule_expression = "rate(3 days)"
}

resource "aws_cloudwatch_event_target" "pexels_scraper_lambda" {
rule = aws_cloudwatch_event_rule.pexels_scraper_periodic.name
target_id = "PexelsScraperLambda"
arn = aws_lambda_function.pexels_image_scraper.arn
}

resource "aws_lambda_permission" "allow_eventbridge" {
statement_id = "AllowExecutionFromEventBridge"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.pexels_image_scraper.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.pexels_scraper_periodic.arn
}
10 changes: 0 additions & 10 deletions apps/railgunbreaker/usw2dev/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ output "acm_certificate_subject_alternative_names" {
value = aws_acm_certificate.rb_website.subject_alternative_names
}

# output "lambda_ecr_repository_url" {
# description = "URL of the ECR repository for the lambda container image"
# value = aws_ecr_repository.lambda_container_repo.repository_url
# }

# output "lambda_ecr_repository_arn" {
# description = "ARN of the ECR repository for the lambda container image"
# value = aws_ecr_repository.lambda_container_repo.arn
# }

# output "event_bridge_rule_name" {
# description = "Name of the EventBridge rule that triggers the Pexels image scraper lambda"
# value = aws_cloudwatch_event_rule.pexels_scraper_periodic.name
Expand Down
11 changes: 11 additions & 0 deletions apps/railgunbreaker/usw2dev/remote_states.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ data "terraform_remote_state" "dns" {
}
}
}

data "terraform_remote_state" "portfolio_website" {
backend = "remote"

config = {
organization = "perry-zhu-aws"
workspaces = {
name = "portfolio-website-usw2dev"
}
}
}
1 change: 1 addition & 0 deletions apps/railgunbreaker/usw2dev/terraform.auto.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
env_name = "usw2dev"
github_repo = "RailgunBreaker/RailgunBreaker.github.io"
pexels_url = "https://www.pexels.com/@railgunbreaker/featured-uploads/"
12 changes: 11 additions & 1 deletion apps/railgunbreaker/usw2dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ variable "subdomain" {
description = "The subdomain to use for the website"
type = string
default = "railgunbreaker.stage"
}
}

variable "project_name" {
description = "The name of the project"
type = string
default = "rb"
}

variable "pexels_url" {
type = string
}