-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathscheduled-action.test.ts
118 lines (105 loc) · 3.39 KB
/
scheduled-action.test.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
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
import { expect, haveResource, MatchStyle } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as autoscaling from '../lib';
nodeunitShim({
'can schedule an action'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);
// WHEN
asg.scaleOnSchedule('ScaleOutInTheMorning', {
schedule: autoscaling.Schedule.cron({ hour: '8', minute: '0' }),
minCapacity: 10,
});
// THEN
expect(stack).to(haveResource('AWS::AutoScaling::ScheduledAction', {
Recurrence: '0 8 * * *',
MinSize: 10,
}));
test.done();
},
'correctly formats date objects'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);
// WHEN
asg.scaleOnSchedule('ScaleOutInTheMorning', {
schedule: autoscaling.Schedule.cron({ hour: '8' }),
startTime: new Date(Date.UTC(2033, 8, 10, 12, 0, 0)), // JavaScript's Date is a little silly.
minCapacity: 11,
});
// THEN
expect(stack).to(haveResource('AWS::AutoScaling::ScheduledAction', {
StartTime: '2033-09-10T12:00:00Z',
}));
test.done();
},
'autoscaling group has recommended updatepolicy for scheduled actions'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);
// WHEN
asg.scaleOnSchedule('ScaleOutInTheMorning', {
schedule: autoscaling.Schedule.cron({ hour: '8' }),
minCapacity: 10,
});
// THEN
expect(stack).toMatch({
Resources: {
ASG46ED3070: {
Type: 'AWS::AutoScaling::AutoScalingGroup',
Properties: {
MaxSize: '1',
MinSize: '1',
LaunchConfigurationName: { Ref: 'ASGLaunchConfigC00AF12B' },
Tags: [
{
Key: 'Name',
PropagateAtLaunch: true,
Value: 'Default/ASG',
},
],
VPCZoneIdentifier: [
{ Ref: 'VPCPrivateSubnet1Subnet8BCA10E0' },
{ Ref: 'VPCPrivateSubnet2SubnetCFCDAA7A' },
],
},
UpdatePolicy: {
AutoScalingRollingUpdate: {
WaitOnResourceSignals: false,
PauseTime: 'PT0S',
SuspendProcesses: [
'HealthCheck',
'ReplaceUnhealthy',
'AZRebalance',
'AlarmNotification',
'ScheduledActions',
],
},
AutoScalingScheduledAction: {
IgnoreUnmodifiedGroupSizeProperties: true,
},
},
},
},
Parameters: {
SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter: {
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>',
Default: '/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2',
},
},
}, MatchStyle.SUPERSET);
test.done();
},
});
function makeAutoScalingGroup(scope: cdk.Construct) {
const vpc = new ec2.Vpc(scope, 'VPC');
return new autoscaling.AutoScalingGroup(scope, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
machineImage: new ec2.AmazonLinuxImage(),
updateType: autoscaling.UpdateType.ROLLING_UPDATE,
});
}