-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLambda.tf
More file actions
70 lines (55 loc) · 1.45 KB
/
Lambda.tf
File metadata and controls
70 lines (55 loc) · 1.45 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
data "aws_iam_policy_document" "m-lambda" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
data "aws_iam_policy_document" "m-lambda-dynamodb" {
statement {
effect = "Allow"
actions = ["dynamodb:*"]
resources = ["*"]
}
}
resource "aws_iam_role" "LambdaIAM" {
name = "LambdaIAM"
assume_role_policy = data.aws_iam_policy_document.m-lambda.json
inline_policy {
name = "Lambda-DynamoDB"
policy = data.aws_iam_policy_document.m-lambda-dynamodb.json
}
}
variable "PayloadName" {
default = "Payload.zip"
}
variable "FileName" {
default = "GetMetric"
}
variable "Function" {
default = "Execute"
}
data "archive_file" "Archive" {
type = "zip"
source_file = "Source/Python/${var.FileName}.py"
output_path = var.PayloadName
}
resource "aws_lambda_function" "m" {
function_name = "IncrementVisitorMetric"
filename = var.PayloadName
role = aws_iam_role.LambdaIAM.arn
source_code_hash = data.archive_file.Archive.output_base64sha256
handler = "${var.FileName}.${var.Function}"
runtime = "python3.9"
}
resource "aws_lambda_function_url" "m" {
function_name = aws_lambda_function.m.arn
authorization_type = "NONE"
cors {
allow_methods = ["GET", "POST"]
allow_origins = ["https://${var.R53DomainName}", "https://www.${var.R53DomainName}"]
}
}