-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.tf
50 lines (40 loc) · 1.19 KB
/
lambda.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
resource "aws_lambda_function" "news-translater" {
function_name = var.function_name
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_objects.key
runtime = var.runtime
handler = "news-translater.handler"
role = aws_iam_role.lambda_exec.arn
environment {
variables = {
NEWS_API_KEY = var.news_api_key
}
}
}
resource "aws_lambda_function_url" "function_url" {
function_name = aws_lambda_function.news-translater.function_name
authorization_type = "NONE"
}
resource "aws_cloudwatch_log_group" "news-translater" {
name = "/aws/lambda/${aws_lambda_function.news-translater.function_name}"
retention_in_days = var.log_retention_in_days
}
resource "aws_iam_role" "lambda_exec" {
name = "${var.function_name}_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_policy" {
role = aws_iam_role.lambda_exec.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}