-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.ts
76 lines (68 loc) · 1.96 KB
/
handler.ts
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
import 'source-map-support/register'
import * as AWS from 'aws-sdk'
import * as config from './infra-config'
const RDS = new AWS.RDS()
const ECS = new AWS.ECS()
const AutoScaling = new AWS.AutoScaling()
export const shutdown = async (): Promise<any> => {
return Promise.all([
Promise.all(
config.rdsClusterIds.map(id =>
RDS.stopDBCluster({ DBClusterIdentifier: id })
.promise()
.catch(error => {
console.error(`Could not shut down RDS cluster ${id}`, error)
}),
),
),
Promise.all(
config.ecsServices.map(service =>
ECS.updateService({ ...service, desiredCount: 0 })
.promise()
.catch(error => {
console.error(`Could not ramp down ECS service ${service.service}`, error)
}),
),
),
Promise.all(
config.autoScalingGroups.map(asg =>
AutoScaling.updateAutoScalingGroup({ ...asg, DesiredCapacity: 0, MinSize: 0 })
.promise()
.catch(error => {
console.error(`Could not ramp down ASG ${asg.AutoScalingGroupName}`, error)
}),
),
),
])
}
export const startup = async (): Promise<any> => {
return Promise.all([
Promise.all(
config.rdsClusterIds.map(id =>
RDS.startDBCluster({ DBClusterIdentifier: id })
.promise()
.catch(error => {
console.error(`Could not start RDS cluster ${id}`, error)
}),
),
),
Promise.all(
config.ecsServices.map(service =>
ECS.updateService(service)
.promise()
.catch(error => {
console.error(`Could not ramp up ECS service ${service}`, error)
}),
),
),
Promise.all(
config.autoScalingGroups.map(asg =>
AutoScaling.updateAutoScalingGroup(asg)
.promise()
.catch(error => {
console.error(`Could not ramp up ASG ${asg.AutoScalingGroupName}`, error)
}),
),
),
])
}