@@ -43,7 +43,7 @@ resource "aws_sns_topic_subscription" "this" {
4343
4444 topic_arn = join (" " , aws_sns_topic. this . * . arn )
4545 protocol = var. subscribers [each . key ]. protocol
46- endpoint = var . subscribers [ each . key ] . endpoint
46+ endpoint = aws_lambda_function . terraform_lambda_func . arn
4747 endpoint_auto_confirms = var. subscribers [each . key ]. endpoint_auto_confirms
4848 raw_message_delivery = var. subscribers [each . key ]. raw_message_delivery
4949}
@@ -68,4 +68,65 @@ data "aws_iam_policy_document" "sns_topic_policy" {
6868
6969 resources = [aws_sns_topic . this [count . index ]. arn ]
7070 }
71+ }
72+
73+ resource "aws_iam_role" "lambda_role" {
74+ name = " S3cloudHub_Test_Lambda_Function_Role"
75+ assume_role_policy = << EOF
76+ {
77+ "Version": "2012-10-17",
78+ "Statement": [
79+ {
80+ "Action": "sts:AssumeRole",
81+ "Principal": {
82+ "Service": "lambda.amazonaws.com"
83+ },
84+ "Effect": "Allow",
85+ "Sid": ""
86+ }
87+ ]
88+ }
89+ EOF
90+ }
91+ resource "aws_iam_policy" "iam_policy_for_lambda" {
92+
93+ name = " aws_iam_policy_for_terraform_aws_lambda_role"
94+ path = " /"
95+ description = " AWS IAM Policy for managing aws lambda role"
96+ policy = << EOF
97+ {
98+ "Version": "2012-10-17",
99+ "Statement": [
100+ {
101+ "Action": [
102+ "logs:CreateLogGroup",
103+ "logs:CreateLogStream",
104+ "logs:PutLogEvents"
105+ ],
106+ "Resource": "arn:aws:logs:*:*:*",
107+ "Effect": "Allow"
108+ }
109+ ]
110+ }
111+ EOF
112+ }
113+
114+ resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
115+ role = aws_iam_role. lambda_role . name
116+ policy_arn = aws_iam_policy. iam_policy_for_lambda . arn
117+ }
118+
119+ data "archive_file" "zip_the_python_code" {
120+ type = " zip"
121+ source_dir = " ${ path . module } /python/"
122+ output_path = " ${ path . module } /python/hello-python.zip"
123+ }
124+
125+ resource "aws_lambda_function" "terraform_lambda_func" {
126+ filename = " ${ path . module } /python/hello-python.zip"
127+ function_name = var. lambda_function_name
128+ role = aws_iam_role. lambda_role . arn
129+ handler = " index.lambda_handler"
130+ runtime = var. lambda_function_runtime
131+ depends_on = [aws_iam_role_policy_attachment . attach_iam_policy_to_iam_role ]
71132}
0 commit comments