-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcfn-template.yaml
193 lines (182 loc) · 5.08 KB
/
cfn-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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
---
Parameters:
AwsRegionName:
Type: String
Default: us-east-1
TagName:
Type: String
Default: MakeSnapshot
TagValue:
Type: String
Default: true
TagType:
Type: String
Default: volume
RunningOnly:
Type: String
Default: ""
KeepDay:
Type: Number
Default: 7
KeepWeek:
Type: Number
Default: 4
KeepMonth:
Type: Number
Default: 12
KeepYear:
Type: Number
Default: 9999
SkipCreate:
Type: String
Default: ""
SkipDelete:
Type: String
Default: ""
S3Bucket:
Type: String
S3Key:
Type: String
Resources:
Makesnap3Policy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
# DescribeAvailabilityZones allow only needed if you are tagging instances rather than volumes
-
Effect: Allow
Action: "ec2:DescribeAvailabilityZones"
Resource: "*"
-
Effect: Allow
Action:
- "ec2:CreateSnapshot"
- "ec2:CreateTags"
- "ec2:DeleteSnapshot"
- "ec2:DescribeSnapshots"
- "ec2:DescribeInstances"
- "ec2:DescribeTags"
- "ec2:DescribeVolumeAttribute"
- "ec2:DescribeVolumeStatus"
- "ec2:DescribeVolumes"
Resource: "*"
Makesnap3Role:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Effect: Allow
Action: "sts:AssumeRole"
Principal:
Service: "lambda.amazonaws.com"
ManagedPolicyArns:
- !Ref Makesnap3Policy
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Makesnap3Function:
Type: "AWS::Lambda::Function"
Properties:
Code:
S3Bucket: !Ref S3Bucket
S3Key: !Ref S3Key
Handler: "makesnap3.lambda_handler"
MemorySize: "128"
Role: !GetAtt Makesnap3Role.Arn
Runtime: "python2.7"
Timeout: "300"
Environment:
Variables:
makesnap_ec2_region_name: !Ref AwsRegionName
makesnap_tag_name: !Ref TagName
makesnap_tag_value: !Ref TagValue
makesnap_tag_type: !Ref TagType
makesnap_running_only: !Ref RunningOnly
makesnap_keep_day: !Ref KeepDay
makesnap_keep_week: !Ref KeepWeek
makesnap_keep_month: !Ref KeepMonth
makesnap_keep_year: !Ref KeepYear
makesnap_skip_create: !Ref SkipCreate
makesnap_skip_delete: !Ref SkipDelete
# Makesnap3HourlyRule:
# Type: "AWS::Events::Rule"
# Properties:
# ScheduleExpression: cron(15 */8 * * ? *)"
# Targets:
# -
# Arn: !GetAtt Makesnap3Function.Arn
# Id: "1"
# Input: "{\"period\": \"day\"}"
#
# Makesnap3HourlyPermission:
# Type: "AWS::Lambda::Permission"
# Properties:
# FunctionName: !Ref Makesnap3Function
# Action: "lambda:InvokeFunction"
# Principal: "events.amazonaws.com"
# SourceArn: !GetAtt Makesnap3HourlyRule.Arn
Makesnap3DailyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 1 ? * MON-SAT *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"day\"}"
Makesnap3DailyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3DailyRule.Arn
Makesnap3WeeklyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 2 ? * SUN *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"week\"}"
Makesnap3WeeklyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3WeeklyRule.Arn
Makesnap3MonthlyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 3 1 * ? *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"month\"}"
Makesnap3MonthlyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3MonthlyRule.Arn
Makesnap3YearlyRule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "cron(30 4 1 1 ? *)"
Targets:
-
Arn: !GetAtt Makesnap3Function.Arn
Id: "1"
Input: "{\"period\": \"year\"}"
Makesnap3YearlyPermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Ref Makesnap3Function
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt Makesnap3YearlyRule.Arn