-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuro_to_inr.tf
108 lines (93 loc) · 2.58 KB
/
euro_to_inr.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
terraform {
required_providers {
aws = {
source = "hashicorp/aws",
"version" = "~> 3.0"
}
}
}
provider "aws" {
region = "ap-south-1"
}
resource "aws_iam_role" "iam_euro_to_inr_lambda" {
name = "iam_euro_to_inr_lambda"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_lambda_function" "euro_to_inr" {
function_name = "euro_to_inr"
handler = "index.handler"
role = aws_iam_role.iam_euro_to_inr_lambda.arn
runtime = "nodejs12.x"
timeout = 10
description = "Convert euro to inr and send notification"
filename = "euro_to_inr.zip"
source_code_hash = filebase64sha256("euro_to_inr.zip")
environment {
variables = {
API_KEY = "GET_API_KEY_FIXIR",
SMTP_USERNAME = "[email protected]",
SMTP_PASSWORD = "testing",
RECEIVER_EMAIL = "[email protected]"
}
}
}
resource "aws_cloudwatch_log_group" "euro_to_inr_log_group" {
name = "/aws/lambda/${aws_lambda_function.euro_to_inr.function_name}"
retention_in_days = 1 // I kept 1 because otherwise aws will charge
}
resource "aws_iam_policy" "euro_to_inr_logging_policy" {
name = "euro_to_inr"
path = "/"
description = "IAM policy for euro to inr lambda"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "euro_to_inr_policy_attachment" {
role = aws_iam_role.iam_euro_to_inr_lambda.name
policy_arn = aws_iam_policy.euro_to_inr_logging_policy.arn
}
resource "aws_cloudwatch_event_rule" "every_day" {
name = "every_day"
description = "Fires every day"
schedule_expression = "rate(1 day)"
}
resource "aws_cloudwatch_event_target" "invoke_lambda_every_day" {
rule = "${aws_cloudwatch_event_rule.every_day.name}"
target_id = "lambda"
arn = "${aws_lambda_function.euro_to_inr.arn}"
}
resource "aws_lambda_permission" "allow_cloudwatch_invoke_lambda" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.euro_to_inr.function_name}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.every_day.arn}"
}