-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
97 lines (84 loc) · 2.25 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: cfn-bot - Cloudformation update tweet bot
Globals:
Function:
Timeout: 60
Parameters:
TwitterAccessTokenKey:
Type: String
TwitterAccessTokenSecret:
Type: String
NotificationEmail:
Type: String
Default: [email protected]
MastodonAccessToken:
Type: String
MastodonApiBaseUrl:
Type: String
Resources:
DynamoTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: hash
AttributeType: 'S'
KeySchema:
- AttributeName: hash
KeyType: HASH
BillingMode: PAY_PER_REQUEST
BotFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: cfnbot/build/
Handler: cfnbot.app.lambda_handler
Runtime: python3.7
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "dynamodb:GetItem"
- "dynamodb:PutItem"
Resource: !GetAtt DynamoTable.Arn
Environment:
Variables:
TABLE_NAME: !Ref DynamoTable
TWITTER_ACCESS_TOKEN_KEY: !Ref TwitterAccessTokenKey
TWITTER_ACCESS_TOKEN_SECRET: !Ref TwitterAccessTokenSecret
MASTODON_ACCESS_TOKEN: !Ref MastodonAccessToken
MASTODON_API_BASE_URL: !Ref MastodonApiBaseUrl
Events:
RunBotPeriodically:
Type: Schedule
Properties:
#Schedule: rate(2 minutes)
Schedule: rate(1 hour)
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Protocol: email
Endpoint: !Ref NotificationEmail
ErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref AlarmTopic
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: FunctionName
Value: !Ref BotFunction
MetricName: Errors
Namespace: AWS/Lambda
EvaluationPeriods: 1
Period: 3600
Statistic: Sum
Threshold: '3'
Outputs:
TableName:
Description: Dynamo table name
Value: !Ref DynamoTable
BotFunctionArn:
Description: "First Lambda Function ARN"
Value: !GetAtt BotFunction.Arn