-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
80 lines (75 loc) · 2.1 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Automated process for keeping manual snapshots on aurora
Parameters:
ClusterId:
Type: String
Description: The name of the Aurora Cluster to be snapped
Chron:
Type: String
Description: Chron schedule
Default: rate(7 days)
TTLMetric:
Type: String
Description: Unit for time to live [Ex -> Second | Minute | Hour | Day | Month]
Default: Month
TTL:
Type: Number
Description: Number of units for TTL
Default: 12
BrodcastOnSuccess:
Type: String
Description: Broadcast to SNS Topic on successful snapshots
Default: false
Globals:
Function:
Runtime: nodejs8.10
MemorySize: 128
Timeout: 300
Environment:
Variables:
SNS_TOPIC_ARN: !Ref SNSBroadcast
CLUSTER_ID: !Ref ClusterId
Resources:
# SNS Topic for notifications
SNSBroadcast:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: AuroraSnapperBroadcast
SnapperLambda:
Type: 'AWS::Serverless::Function'
Properties:
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- rds:CreateDBClusterSnapshot
- rds:DeleteDBClusterSnapshot
- rds:DescribeDBClusterSnapshots
Resource: '*'
- Effect: Allow
Action:
- sns:Publish
Resource: !Ref SNSBroadcast
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
Handler: snapper/index.handler
Events:
CreateAuroraSnapshot:
Type: Schedule
Properties:
Schedule: !Ref Chron
Environment:
Variables:
TIME_TO_LIVE: !Ref TTL
TIME_TO_LIVE_METRIC: !Ref TTLMetric
BROADCAST_ON_SUCCESS: !Ref BrodcastOnSuccess
Outputs:
BroadcastTopicArn:
Description: 'SNS Topic Arn for subscriptions for notifications'
Value: !Ref SNSBroadcast