forked from awslabs/aws-serverless-twitter-event-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
82 lines (78 loc) · 2.95 KB
/
template.yml
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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
SearchText:
Type: String
Description: Non-URL-encoded search text poller should use when querying Twitter Search API.
TweetProcessorFunctionName:
Type: String
Description: Name of lambda function that should be invoked to process tweets. Note, this must be a function name and not a function ARN.
SSMParameterPrefix:
Type: String
Default: 'twitter-event-source'
Description: >
This app assumes API keys needed to use the Twitter API are stored as SecureStrings in SSM Parameter Store under the prefix defined by
this parameter. See the app README for details.
PollingFrequencyInMinutes:
Type: Number
MinValue: 1
Default: 1
Description: Frequency in minutes to poll for more tweets.
BatchSize:
Type: Number
MinValue: 1
Default: 15
Description: Max number of tweets to send to the TweetProcessor lambda function on each invocation.
StreamModeEnabled:
Type: String
Default: false
AllowedValues:
- true
- false
Description: If true, the app will remember the last tweet found and only invoke the tweet processor function for newer tweets. If false, the app will be stateless and invoke the tweet processor function with all tweets found in each polling cycle.
Conditions:
IsPollingFrequencyInMinutesSingular: !Equals [!Ref PollingFrequencyInMinutes, 1]
Resources:
TwitterSearchPoller:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
Runtime: python3.6
Handler: poller.handler
Tracing: Active
MemorySize: 128
Timeout: 60
Policies:
- LambdaInvokePolicy:
FunctionName: !Ref TweetProcessorFunctionName
- DynamoDBCrudPolicy:
TableName: !Ref SearchCheckpoint
- Statement:
Effect: Allow
Action:
- ssm:GetParameters
Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${SSMParameterPrefix}/*
Environment:
Variables:
SSM_PARAMETER_PREFIX: !Ref SSMParameterPrefix
SEARCH_TEXT: !Ref SearchText
SEARCH_CHECKPOINT_TABLE_NAME: !Ref SearchCheckpoint
TWEET_PROCESSOR_FUNCTION_NAME: !Ref TweetProcessorFunctionName
BATCH_SIZE: !Ref BatchSize
STREAM_MODE_ENABLED: !Ref StreamModeEnabled
Events:
Timer:
Type: Schedule
Properties:
Schedule: !If [IsPollingFrequencyInMinutesSingular, !Sub 'rate(${PollingFrequencyInMinutes} minute)', !Sub 'rate(${PollingFrequencyInMinutes} minutes)']
SearchCheckpoint:
Type: AWS::Serverless::SimpleTable
Outputs:
TwitterSearchPollerFunctionName:
Value: !Ref TwitterSearchPoller
TwitterSearchPollerFunctionArn:
Value: !GetAtt TwitterSearchPoller.Arn
SearchCheckpointTableName:
Value: !Ref SearchCheckpoint
SearchCheckpointTableArn:
Value: !GetAtt SearchCheckpoint.Arn