Skip to content

Commit 00c5306

Browse files
committed
Initial setup
1 parent 0e9f986 commit 00c5306

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

infrastructure/applications/cluster/iam.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resource "aws_iam_role_policy" "server" {
1515
}
1616

1717
data "aws_iam_policy_document" "server_assume_role" {
18+
# allow ecs
1819
statement {
1920
effect = "Allow"
2021

@@ -25,6 +26,16 @@ data "aws_iam_policy_document" "server_assume_role" {
2526

2627
actions = ["sts:AssumeRole"]
2728
}
29+
30+
# allow lambda
31+
statement {
32+
effect = "Allow"
33+
principals {
34+
type = "Service"
35+
identifiers = ["lambda.amazonaws.com"]
36+
}
37+
actions = ["sts:AssumeRole"]
38+
}
2839
}
2940

3041
data "aws_iam_policy_document" "server_role_policy" {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "aws_lambda_function" "new_file_uploaded" {
2+
function_name = "pythonit-${terraform.workspace}-new-file-uploaded"
3+
package_type = "Image"
4+
image_uri = "${data.aws_ecr_repository.be_repo.repository_url}@${data.aws_ecr_image.be_arm_image.image_digest}"
5+
architectures = ["arm64"]
6+
memory_size = 2048
7+
timeout = 300
8+
role = var.iam_role_arn
9+
10+
environment {
11+
variables = {
12+
for variable in local.env_vars:
13+
variable.name => variable.value
14+
if variable.name != "AWS_DEFAULT_REGION"
15+
}
16+
}
17+
}
18+
19+
resource "aws_lambda_event_source_mapping" "new_file_uploaded" {
20+
event_source_arn = aws_sqs_queue.new_file_uploaded.arn
21+
function_name = aws_lambda_function.new_file_uploaded.function_name
22+
enabled = true
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "aws_sqs_queue" "new_file_uploaded" {
2+
name = "pythonit-${terraform.workspace}-new-file-uploaded"
3+
visibility_timeout_seconds = 300
4+
}
5+
6+
resource "aws_sqs_queue_policy" "new_file_uploaded" {
7+
queue_url = aws_sqs_queue.new_file_uploaded.id
8+
policy = jsonencode({
9+
Version = "2012-10-17"
10+
Statement = [
11+
{
12+
Effect = "Allow"
13+
Principal = {
14+
Service = "s3.amazonaws.com"
15+
}
16+
Action = "sqs:SendMessage"
17+
Resource = aws_sqs_queue.new_file_uploaded.arn
18+
Condition = {
19+
ArnEquals = {
20+
"aws:SourceArn" = aws_s3_bucket.backend_media.arn
21+
}
22+
}
23+
}
24+
]
25+
})
26+
}

infrastructure/applications/pycon_backend/s3.tf renamed to infrastructure/applications/pycon_backend/media_s3.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "backend_media" {
1313
}
1414
}
1515
}
16+
17+
resource "aws_s3_bucket_notification" "new_file_uploaded" {
18+
bucket = aws_s3_bucket.backend_media.id
19+
20+
queue {
21+
queue_arn = aws_sqs_queue.new_file_uploaded.arn
22+
events = ["s3:ObjectCreated:*"]
23+
filter_prefix = "files/"
24+
}
25+
}

0 commit comments

Comments
 (0)