-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
115 lines (105 loc) · 3.05 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
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
AWSTemplateFormatVersion : '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: infrastructurez for the twitter bot
Parameters:
TwitterConsumerKey:
Type: String
TwitterConsumerSecret:
Type: String
TwitterAccessToken:
Type: String
TwitterAccessTokenSecret:
Type: String
LambdaFunctionName:
Type: String
Default: gitwishes-function
DynamoDBTableName:
Type: String
Default: gitwishes-messages
ExcludeRepos:
Type: String
Default: ""
Resources:
GitWishesLambdaBot:
Type: AWS::Serverless::Function
DependsOn:
- GitWishesRole
- GitWishesDB
Properties:
Handler: function.handler
Runtime: python3.6
Role: !GetAtt [GitWishesRole, Arn]
CodeUri: ./dist
FunctionName: !Ref LambdaFunctionName
Environment:
Variables:
TWITTER_CONSUMER_KEY: !Ref TwitterConsumerKey
TWITTER_CONSUMER_SECRET: !Ref TwitterConsumerSecret
TWITTER_ACCESS_TOKEN: !Ref TwitterAccessToken
TWITTER_ACCESS_TOKEN_SECRET: !Ref TwitterAccessTokenSecret
DB_TABLE_NAME: !Ref DynamoDBTableName
EXCLUDE_REPOS: !Ref ExcludeRepos
GitWishesRole:
Type: AWS::IAM::Role
Properties:
RoleName: gitwishes-service-role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
GitWishesDB:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref DynamoDBTableName
KeySchema:
- AttributeName: MessageBody
KeyType: HASH
AttributeDefinitions:
- AttributeName: MessageBody
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: "1"
WriteCapacityUnits: "1"
TimeToLiveSpecification:
AttributeName: TTL
Enabled: true
CommitSearchEventRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(0 6 * * ? *)"
Name: CommitSearchEvent
State: "ENABLED"
Targets:
-
Arn: !GetAtt GitWishesLambdaBot.Arn
Id: "CommitSearchEventScheduler"
TweetEventRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "rate(4 hours)"
Name: TweetEvent
State: "ENABLED"
Targets:
-
Arn: !GetAtt GitWishesLambdaBot.Arn
Id: "TweetEventScheduler"
CommitSearchEventLambdaPermissions:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref LambdaFunctionName
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt [CommitSearchEventRule, Arn]
TweetEventLambdaPermissions:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref LambdaFunctionName
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt [TweetEventRule, Arn]