resource "aws_iam_role" "lambda_role" { name = "lambda_s3_write_role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Effect = "Allow" Principal = { Service = "lambda.amazonaws.com" } } ] }) } resource "aws_iam_policy" "lambda_s3_write_policy" { name = "lambda_s3_write_policy" description = "Policy for Lambda to write to S3 bucket ${var.deflock_stats_bucket}" policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = [ "s3:PutObject", "s3:PutObjectAcl" ] Effect = "Allow" Resource = "arn:aws:s3:::${var.deflock_stats_bucket}/${var.output_filename}" } ] }) } resource "aws_iam_role_policy_attachment" "lambda_s3_write_attachment" { role = aws_iam_role.lambda_role.name policy_arn = aws_iam_policy.lambda_s3_write_policy.arn } resource "null_resource" "pip_install" { provisioner "local-exec" { command = <