-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
158 lines (143 loc) · 4.17 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
155
156
157
158
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 30
Parameters:
TwitterHashtagParam:
Type: String
Default: CoronaVirus
Description: Twitter hashtag value to track
TwitterTweetCount:
Type: Number
Default: 10
MaxValue: 100
MinValue: 1
Description: Number of popular tweets to store in DynamoDB during lambda execution time
DynamoDBTablename:
Type: String
Default: twitter-table-dev
Description: DynamoDB table name
TwitterComsumerKey:
Type: String
Description: Twitter app Consumer Key
TwitterConsumerSecret:
Type: String
Description: Twitter app Consumer Secret
TwitterAccessToken:
Type: String
Description: Twitter app Access Token
TwitterAccessTokenSecret:
Type: String
Description: Twitter app Access Token Secret
Resources:
HashTagSimpleAnalyticFunction:
Type: AWS::Serverless::Function
Properties:
Description: Access tweets by hashtag and query params
FunctionName: hashtag-analytics
CodeUri: ./hashtag-analytics-lambda
Handler: app.lambda_handler
Runtime: nodejs12.x
MemorySize: 256
Policies:
- DynamoDBReadPolicy:
TableName: !Ref DynamoDBDataStore
Environment:
Variables:
TABLE_NAME: !Ref DynamoDBDataStore
Events:
GetTweets:
Type: Api
Properties:
Path: /tweets
Method: GET
RestApiId:
Ref: HashTagAnalyticsApi
TwitterSearchFunction:
Type: AWS::Serverless::Function
Properties:
Description: Twitter hashtag tracker
FunctionName: hashtracker
CodeUri: ./hashtag-tracker-lambda
Handler: app.lambda_handler
Runtime: nodejs12.x
MemorySize: 256
Policies:
- DynamoDBWritePolicy:
TableName: !Ref DynamoDBDataStore
Environment:
Variables:
TABLE_NAME: !Ref DynamoDBDataStore
HASHTAG: !Ref TwitterHashtagParam
TWEET_COUNT: !Ref TwitterTweetCount
TWITTER_CONSUMER_KEY: !Ref TwitterComsumerKey
TWITTER_CONSUMER_SECRET: !Ref TwitterConsumerSecret
TWITTER_ACCESS_TOKEN_KEY: !Ref TwitterAccessToken
TWITTER_ACCESS_TOKEN_SECRET: !Ref TwitterAccessTokenSecret
Events:
Timer:
Type: Schedule
Properties:
Schedule: rate(60 minutes)
DependsOn: DynamoDBDataStore
DynamoDBDataStore:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref DynamoDBTablename
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: N
- AttributeName: retweet_count
AttributeType: N
- AttributeName: favorite_count
AttributeType: N
- AttributeName: tweet_created_at
AttributeType: S
LocalSecondaryIndexes:
- IndexName: retweet_count-index
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: retweet_count
KeyType: RANGE
Projection:
ProjectionType: ALL
- IndexName: favorite_count-index
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: favorite_count
KeyType: RANGE
Projection:
ProjectionType: ALL
- IndexName: tweet_created_at-index
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: tweet_created_at
KeyType: RANGE
Projection:
ProjectionType: ALL
HashTagAnalyticsApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
EndpointConfiguration: REGIONAL
OpenApiVersion: 3.0.3
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: hashtag-tracker-openapi.yaml
Outputs:
ApiUrl:
Description: "API url of the dev environment"
Value: !Sub "https://${HashTagAnalyticsApi}.execute-api.${AWS::Region}.amazonaws.com/dev/"