Skip to content

Commit

Permalink
Adding condition on s3 event bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
amarouane-ABDELHAK committed Nov 13, 2024
1 parent 685e7db commit b258d41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sm2a/infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "random_password" "password" {


module "sma-base" {
source = "https://github.com/NASA-IMPACT/self-managed-apache-airflow/releases/download/v1.1.4/self-managed-apache-airflow.zip"
source = "https://github.com/NASA-IMPACT/self-managed-apache-airflow/releases/download/v1.1.5/self-managed-apache-airflow.zip"
project = var.project_name
airflow_db = var.airflow_db
fernet_key = var.fernet_key
Expand Down
15 changes: 10 additions & 5 deletions sm2a/infrastructure/s3_event_bridge_lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ data "archive_file" "python_lambda_package" {


resource "aws_lambda_function" "lambda" {
count = var.eis_storage_bucket_name != null ? 1 : 0

provider = aws.aws_current
filename = "/tmp/s3_event_bridge_to_sfn_execute.zip"
Expand All @@ -127,14 +128,16 @@ resource "aws_lambda_function" "lambda" {
variables = {
TARGET_DAG_ID = var.target_dag_id
SM2A_SECRET_MANAGER_NAME = var.sm2a_secret_manager_name
STORAGE_BUCKET = var.storage_bucket_name
S3_FILTER_PREFIX = var.s3_invoke_filter_prefix
STORAGE_BUCKET = var.eis_storage_bucket_name
S3_FILTER_PREFIX = var.eis_s3_invoke_filter_prefix
}
}
}

resource "aws_cloudwatch_log_group" "group" {

count = var.eis_storage_bucket_name != null ? 1 : 0


provider = aws.aws_current
name = "/aws/lambda/${aws_lambda_function.lambda.function_name}"
Expand All @@ -146,25 +149,27 @@ resource "aws_cloudwatch_log_group" "group" {
#####################################################

resource "aws_lambda_permission" "s3_invoke" {
count = var.eis_storage_bucket_name != null ? 1 : 0

provider = aws.aws_current
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda.function_name
principal = "s3.amazonaws.com"
statement_id = "AllowInvocationFromS3Bucket-veda-${var.stage}"
source_arn = "arn:aws:s3:::${var.storage_bucket_name}"
source_arn = "arn:aws:s3:::${var.eis_storage_bucket_name}"
}




resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = var.storage_bucket_name
count = var.eis_storage_bucket_name != null ? 1 : 0
bucket = var.eis_storage_bucket_name

lambda_function {
lambda_function_arn = aws_lambda_function.lambda.arn
events = ["s3:ObjectCreated:*"]
filter_prefix = var.s3_invoke_filter_prefix
filter_prefix = var.eis_s3_invoke_filter_prefix
filter_suffix = ".gpkg"
}

Expand Down
4 changes: 2 additions & 2 deletions sm2a/infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ variable "stac_url" {
variable "vector_secret_name" {
}

variable "storage_bucket_name" {
variable "eis_storage_bucket_name" {
}

variable "s3_invoke_filter_prefix" {
variable "eis_s3_invoke_filter_prefix" {
}
variable "sm2a_secret_manager_name" {
}
Expand Down

0 comments on commit b258d41

Please sign in to comment.