Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nivleshc/0f7f7f9c350c8204f9166c23e1cf050d to your computer and use it in GitHub Desktop.

Select an option

Save nivleshc/0f7f7f9c350c8204f9166c23e1cf050d to your computer and use it in GitHub Desktop.
This gist contains code from lambda.tf, which is part of the blog-amazon-macie-custom-eventbridge-events repository.
# Lambda function that processes Macie job status events from CloudWatch Logs
# and publishes them as custom events to EventBridge
resource "aws_lambda_function" "macie_job_status" {
function_name = local.lambda_function.function_name
description = local.lambda_function.description
role = aws_iam_role.lambda_execution_role.arn
handler = local.lambda_function.handler
runtime = local.lambda_function.runtime
timeout = local.lambda_function.timeout
memory_size = local.lambda_function.memory_size
filename = data.archive_file.lambda_function.output_path
source_code_hash = data.archive_file.lambda_function.output_base64sha256
environment {
variables = {
EVENT_BUS_NAME = local.eventbridge.event_bus_name
EVENT_SOURCE = local.eventbridge.event_source
DETAIL_TYPE = local.eventbridge.detail_type
}
}
}
# CloudWatch Log Group for the Lambda function
resource "aws_cloudwatch_log_group" "lambda" {
name = "/aws/lambda/${local.lambda_function.function_name}"
retention_in_days = 30
}
# Permission for CloudWatch Logs to invoke the Lambda function
resource "aws_lambda_permission" "allow_cloudwatch_logs" {
statement_id = "AllowExecutionFromCloudWatchLogs"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.macie_job_status.function_name
principal = "logs.${data.aws_region.current.name}.amazonaws.com"
source_arn = "${aws_cloudwatch_log_group.macie_jobs.arn}:*"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment