-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamodb.tf
134 lines (125 loc) · 2.94 KB
/
dynamodb.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
resource "aws_dynamodb_table" "user" {
name = "user"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "alias"
attribute {
name = "alias"
type = "S"
}
}
resource "aws_dynamodb_table" "feed" {
name = "feed"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "alias"
range_key = "timestamp"
attribute {
name = "alias"
type = "S"
}
attribute {
name = "timestamp"
type = "N"
}
}
resource "aws_dynamodb_table" "story" {
name = "story"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "alias"
range_key = "timestamp"
attribute {
name = "alias"
type = "S"
}
attribute {
name = "timestamp"
type = "N"
}
}
resource "aws_dynamodb_table" "token" {
name = "token"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "tokenString"
range_key = "alias"
attribute {
name = "tokenString"
type = "S"
}
attribute {
name = "alias"
type = "S"
}
global_secondary_index {
name = "aliasIndex"
hash_key = "alias"
range_key = "tokenString"
write_capacity = 1
read_capacity = 1
projection_type = "ALL"
}
ttl {
attribute_name = "expiration"
enabled = true
}
}
resource "aws_dynamodb_table" "follow" {
name = "follow"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1
hash_key = "followerAlias"
range_key = "followeeAlias"
attribute {
name = "followerAlias"
type = "S"
}
attribute {
name = "followeeAlias"
type = "S"
}
global_secondary_index {
name = "followsIndex"
hash_key = "followeeAlias"
range_key = "followerAlias"
write_capacity = 1
read_capacity = 1
projection_type = "ALL"
}
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
resource "aws_iam_policy" "dynamo_request" {
name = "tweeter-dynamo-request"
path = "/"
policy = jsonencode({
Version : "2012-10-17",
Statement : [
{
Action : [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:Scan",
"dynamodb:DeleteItem",
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:BatchWriteItem"
],
Resource : "arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/*",
Effect : "Allow"
}
]
})
}
resource "aws_iam_role_policy_attachment" "dynamo_request" {
policy_arn = aws_iam_policy.dynamo_request.arn
role = aws_iam_role.lambda_role.name
}