-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlambda.tf
More file actions
86 lines (70 loc) · 2.15 KB
/
Copy pathlambda.tf
File metadata and controls
86 lines (70 loc) · 2.15 KB
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
module "create_url_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "~> 7.7.0"
function_name = "shortener-url-create"
description = "Lambda function to create URL"
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
publish = true
lambda_role = module.lambda_role.iam_role_arn
create_role = false
tracing_mode = "Active"
create_package = true
source_path = "./url-create-lambda/"
allowed_triggers = {
AllowExecutionFromAPIGateway = {
service = "apigateway"
}
}
environment_variables = {
APP_URL = "https://shortener.sctp-sandbox.com/"
MAX_CHAR = "16"
MIN_CHAR = "12"
REGION_AWS = data.aws_region.current.region
DB_NAME = aws_dynamodb_table.shortener_table.name
}
}
module "retrieve_url_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "~> 7.7.0"
function_name = "shortener-url-retrieve"
description = "Lambda function to retrieve URL"
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
publish = true
create_role = false
lambda_role = module.lambda_role.iam_role_arn
tracing_mode = "Active"
create_package = true
source_path = "./url-retrieve-lambda/"
allowed_triggers = {
AllowExecutionFromAPIGateway = {
service = "apigateway"
}
}
environment_variables = {
REGION_AWS = data.aws_region.current.region
DB_NAME = aws_dynamodb_table.shortener_table.name
}
}
module "lambda_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = "~> 5.30.0"
trusted_role_services = [
"lambda.amazonaws.com"
]
create_role = true
role_name = "shortener-lambda-role"
role_requires_mfa = false
custom_role_policy_arns = [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess",
module.lambda_policy.arn,
]
}
module "lambda_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "~> 5.30.0"
name = "shortener-lambda-policy"
policy = data.aws_iam_policy_document.lambda_policy.json
}