-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtemplate.yaml
More file actions
106 lines (100 loc) · 3.12 KB
/
template.yaml
File metadata and controls
106 lines (100 loc) · 3.12 KB
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
ecs-shutdown-scheduler
Sample SAM Template for ecs-shutdown-scheduler
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
Parameters:
Whitelist:
Type: String
Default: "dev,test"
StartSchedule:
Type: String
Default: "cron(0 7 * * ? *)"
ShutdownSchedule:
Type: String
Default: "cron(0 21 * * ? *)"
Resources:
LambdaFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ecs_shutdown_scheduler/src
Handler: schedule_containers.lambda_handler
Runtime: python3.8
Role: !GetAtt LambdaRole.Arn
Environment:
Variables:
LOG_LEVEL: INFO
WHITELIST: !Ref Whitelist
Events:
Start:
Type: Schedule
Properties:
Schedule: !Ref StartSchedule
Input: "{\"Task\": \"start\"}"
Shutdown:
Type: Schedule
Properties:
Schedule: !Ref ShutdownSchedule
Input: "{\"Task\": \"shutdown\"}"
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
-
PolicyName: "Autoscaling"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "Autoscaling"
Effect: "Allow"
Action:
- "application-autoscaling:DescribeScalableTargets"
- "application-autoscaling:RegisterScalableTarget"
Resource: "*"
-
PolicyName: "ECS"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "List"
Effect: "Allow"
Action:
- "ecs:ListClusters"
- "ecs:ListServices"
Resource: "*"
-
Sid: "Services"
Effect: "Allow"
Action:
- "ecs:UpdateService"
- "ecs:DescribeServices"
Resource: !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:service/*"
-
PolicyName: "ParameterStore"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "ParameterStore"
Effect: "Allow"
Action:
- "ssm:GetParameter"
- "ssm:PutParameter"
Resource: !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/ecs-shutdown-scheduler/*"