-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.yaml
154 lines (146 loc) · 4.46 KB
/
template.yaml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
AWSTemplateFormatVersion: 2010-09-09
Description: A template for launching the message_followers auto responder
Parameters:
ConsumerKey:
Type: String
NoEcho: True
ConsumerSecret:
Type: String
NoEcho: True
AccessTokenKey:
Type: String
NoEcho: True
AccessTokenSecret:
Type: String
NoEcho: True
Message:
Type: String
Description: The text you want to send to your new followers
ReadCapacityUnits:
Type: Number
Default: 5
MaxValue: 1000
MinValue: 5
Description: Set this to the current number of followers divided by 300 or you can leave the default and your function will execute more slowly.
WriteCapacityUnits:
Type: Number
Default: 25
MaxValue: 1000
MinValue: 5
Description: Set this to the current number of followers divided by 300. It will be lowered after all of your followers are lowered.
Resources:
TwitterFollowers:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: follower
AttributeType: N
KeySchema:
-
AttributeName: follower
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: !Ref ReadCapacityUnits
WriteCapacityUnits: !Ref WriteCapacityUnits
MessageFollowersRole:
Type: AWS::IAM::Role
DependsOn: TwitterFollowers
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: root
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: logs:*
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- dynamodb:DeleteItem
- dynamodb:GetRecords
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
- dynamodb:BatchWriteItem
- dynamodb:BatchGetItem
- dynamodb:BatchGetItem
- dynamodb:UpdateTable
Resource: !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${TwitterFollowers}
LoadFollowers:
Type: AWS::Lambda::Function
DependsOn:
- TwitterFollowers
- MessageFollowersRole
Properties:
Code:
S3Bucket: !Sub randhunt-code-${AWS::Region}
S3Key: message_followers.zip
Description: Load in all of your existing followers
Handler: load_followers.lambda_handler
Runtime: python2.7
Timeout: 300
MemorySize: 256
Role: !GetAtt MessageFollowersRole.Arn
Environment:
Variables:
CONSUMER_KEY: !Ref ConsumerKey
CONSUMER_SECRET: !Ref ConsumerSecret
ACCESS_TOKEN_KEY: !Ref AccessTokenKey
ACCESS_TOKEN_SECRET: !Ref AccessTokenSecret
DDB_TABLE: !Ref TwitterFollowers
DDB_READ_UNITS: !Ref ReadCapacityUnits
LoadData:
Type: Custom::LoadData
Properties:
ServiceToken: !GetAtt LoadFollowers.Arn
MessageFollowers:
Type: AWS::Lambda::Function
DependsOn:
- LoadData
- LoadFollowers
Properties:
Description: Loop through followers and tweet at each new follower
Handler: message_followers.lambda_handler
Runtime: python2.7
Code:
S3Bucket: !Sub randhunt-code-${AWS::Region}
S3Key: message_followers.zip
MemorySize: 256
Timeout: 300
Role: !GetAtt MessageFollowersRole.Arn
Environment:
Variables:
CONSUMER_KEY: !Ref ConsumerKey
CONSUMER_SECRET: !Ref ConsumerSecret
ACCESS_TOKEN_KEY: !Ref AccessTokenKey
ACCESS_TOKEN_SECRET: !Ref AccessTokenSecret
DDB_TABLE: !Ref TwitterFollowers
MESSAGE: !Ref Message
MessageFollowersEveryFiveMinutes:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: rate(5 minutes)
State: ENABLED
Targets:
-
Arn: !GetAtt MessageFollowers.Arn
Id: MessageFollowers
PermissionForEventsToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt MessageFollowers.Arn
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt MessageFollowersEveryFiveMinutes.Arn