Skip to content

Instantly share code, notes, and snippets.

View nhammad's full-sized avatar

nhammad

View GitHub Profile
module "schedule_test_module" {
source = "../_modules/.."
config = module.config
schedule = "cron(0/10 * ? * MON-FRI *)"
}
import logging
import os
import boto3
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
logger.info(f'Hello World!')
resource "aws_secretsmanager_secret" "pipeline_password" {
name = "pipeline_pwd"
description = "pipeline pwd for triggering bitbucket pipeline"
tags = "-"
}
data "aws_s3_bucket" "run_pipeline" {
bucket = local.bucket_name
}
resource "aws_s3_bucket_notification" "run_pipeline" {
bucket = data.aws_s3_bucket.run_pipeline.id
lambda_function {
lambda_function_arn = aws_lambda_function.processing_lambda.arn
events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*", "s3:ObjectRestore:*"]
data "archive_file" "lambda_zip" {
type = "zip"
source_file = "${path.module}/src/run_pipeline.py"
output_file_mode = "0666"
output_path = "${path.module}/bin/run_pipeline.zip"
}
resource "aws_lambda_function" "processing_lambda" {
filename = data.archive_file.lambda_zip.output_path
function_name = local.processing_lambda_name
module "run_pipeline" {
bucket_name = module.s3_buckets.name
s3_prefix = "testfolder/"
s3_suffix = ".zip"
pipeline_name = "dbt-validation"
bitbucket_branch_name = "default"
bitbucket_repo_owner = "username"
bitbucket_repo_slug = "reponame"
}
import logging
import os
import urllib3
import json
import boto3
import base64
from botocore.exceptions import ClientError
logger = logging.getLogger()
logger.setLevel(logging.INFO)
resource "aws_iam_role_policy" "lambda" {
name = "s3_policy"
role = aws_iam_role.conversion_lambda_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
resource "aws_s3_bucket_notification" "incoming" {
bucket = aws_s3_bucket.incoming.id
lambda_function {
lambda_function_arn = aws_lambda_function.conversion_lambda.arn
events = ["s3:ObjectCreated:*"]
filter_prefix = "foldername"
filter_suffix = ".zip"
}
data "archive_file" "lambda_zip" {
type = "zip"
source_file = "${path.module}/src/conversion_lambda_python_file.py"
output_file_mode = "0666"
output_path = "${path.module}/bin/conversion_lambda_python_file.zip"
}
resource "aws_lambda_function" "conversion_lambda" {
runtime = "python3.9"
filename = data.archive_file.lambda_zip.output_path