forked from aws-samples/aws-scheduled-event-adjuster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
120 lines (109 loc) · 3.35 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
scheduled-event-adjuster
This solution adjusts the schedules of scheduled Auto Scaling Group scaling
actions to account for hour changes due to Daylight Saving Time.
Parameters:
NotificationEmail:
Type: String
Description: The email address that should be notified when relevant events
occur.
TagPrefix:
Type: String
Description: (Optional) The tag prefix to use when checking resources'
tags. Leave empty to use the default prefix.
Default: 'scheduled-event-adjuster'
Globals:
Function:
Timeout: 10
Resources:
AdjustScheduleFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: adjust_schedule_function
Handler: adjust_schedule/app.lambda_handler
Runtime: python3.7
Environment:
Variables:
TAG_PREFIX: !Ref TagPrefix
Policies:
- Version: '2012-10-17'
Statement:
- Sid: 'AllowProcessingAutoScalingGroups'
Effect: 'Allow'
Action:
- 'autoscaling:DescribeAutoScalingGroups'
- 'autoscaling:DescribeScheduledActions'
- 'autoscaling:BatchPutScheduledUpdateGroupAction'
Resource: '*'
- Sid: 'AllowProcessingEventBridgeRules'
Effect: 'Allow'
Action:
- 'events:ListRules'
- 'events:ListTagsForResource'
- 'events:PutRule'
Resource: '*'
- EventBridgePutEventsPolicy:
EventBusName: default
Trigger:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- scheduled-event-adjuster
detail-type:
- 'ManualTrigger'
ScheduleExpression: cron(0 0,12 * * ? *)
State: ENABLED
Targets:
- Arn: !GetAtt AdjustScheduleFunction.Arn
Id: adjust-schedule-lambda-function
TriggerPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt AdjustScheduleFunction.Arn
Principal: events.amazonaws.com
SourceArn: !GetAtt Trigger.Arn
#
# EventBridge subscription to notify about a completion via SNS
#
CompletionNotificationTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: !Ref NotificationEmail
Protocol: email
CompletionNotificationTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Id: 'CompletionNotificationTopicPolicy'
Version: '2012-10-17'
Statement:
- Sid: 'AllowPublishingFromEventBridge'
Effect: 'Allow'
Principal:
Service: 'events.amazonaws.com'
Action: 'sns:Publish'
Resource: !Ref CompletionNotificationTopic
Topics:
- !Ref CompletionNotificationTopic
NotifyOnCompletion:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- scheduled-event-adjuster
detail-type:
- 'ProcessCompleted'
State: ENABLED
Targets:
- Arn: !Ref CompletionNotificationTopic
Id: completion-notification-sns-topic
#
# End of subscription
#