forked from NicolaivdSmagt/lambda-url-shortening
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
83 lines (79 loc) · 1.65 KB
/
main.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
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_dynamodb_table" "redir_urls" {
name = "redir_urls"
read_capacity = 1
write_capacity = 1
hash_key = "token"
stream_enabled = false
attribute {
name = "token"
type = "S"
}
}
resource "aws_iam_role_policy" "redir_logs_rw" {
name = "redir_logs_rw"
role = "${aws_iam_role.lambda_redir.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CloudWatchRW",
"Resource": "*",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy" "redir_data_rw" {
name = "redir_data_rw"
role = "${aws_iam_role.lambda_redir.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DynamoDBRW",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:Get*",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role" "lambda_redir" {
name = "lambda_redir"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}