-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlocust-cloudwatch.yml
241 lines (219 loc) · 6.88 KB
/
locust-cloudwatch.yml
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template for launching a Locust load generator and Concurrency
Labs CloudWatch Connector module. This template creates an IAM role and an EC2 instance profile,
so the Locust EC2 instance can call CloudWatch APIs. This template does not create CloudWatch Logs
log groups or log streams, since the CloudWatch Connector module creates them.
Mappings:
RegionMap:
us-east-1:
#Find the latest image using: aws ec2 describe-images, for example:
#aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn-ami-hvm-2018.03.0.20180811-x86_64-gp2" --region us-east-1
AMI: ami-00eb20669e0990cb4
Outputs:
LocustServerInstanceId:
Description: The instance ID of the Locust server
Value:
Ref: LocustServer
PublicIP:
Description: Public IP address of the Locust server
Value:
Fn::GetAtt:
- LocustServer
- PublicIp
Parameters:
InstanceTypeParameter:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.medium
- t2.large
- m4.large
Description: Select an EC2 instance type
KeyName:
ConstraintDescription: must be the name of an existing EC2 KeyPair.
Description: Name of an existing EC2 KeyPair to enable SSH access to the Locust instances
Type: AWS::EC2::KeyPair::KeyName
Resources:
LocustServer:
CreationPolicy:
ResourceSignal:
Timeout: PT10M
Metadata:
AWS::CloudFormation::Init:
configSets:
install_all:
- install_cfn
- install_packages
install_cfn:
files:
/etc/cfn/cfn-hup.conf:
content:
Fn::Join:
- ''
- - '[main]
'
- stack=
- Ref: AWS::StackId
- '
'
- region=
- Ref: AWS::Region
- '
'
group: root
mode: '000400'
owner: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content:
Fn::Join:
- ''
- - '[cfn-auto-reloader-hook]
'
- 'triggers=post.update
'
- 'path=Resources.LocustServer.Metadata.AWS::CloudFormation::Init
'
- 'action=/opt/aws/bin/cfn-init -v '
- ' --stack '
- Ref: AWS::StackName
- ' --resource LocustServer '
- ' --configsets install_all '
- ' --region '
- Ref: AWS::Region
- '
'
- 'runas=root
'
services:
sysvinit:
cfn-hup:
enabled: 'true'
ensureRunning: 'true'
files:
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf
install_packages:
packages:
yum:
python36: []
gcc: []
gcc-c++ : []
commands:
install_locust:
command: "pip install locustio"
install_pyzmq:
command: "pip install pyzmq"
install_boto3:
command: "pip install boto3"
Comment: Install CloudFormation and Locust
Properties:
IamInstanceProfile:
Ref: LocustCWConnectorInstanceProfile
ImageId:
Fn::FindInMap:
- RegionMap
- Ref: AWS::Region
- AMI
InstanceType:
Ref: InstanceTypeParameter
KeyName:
Ref: KeyName
SecurityGroups:
- Ref: LocustServerSecurityGroup
Tags:
- Key: Name
Value: locust-server
UserData:
Fn::Base64:
Fn::Join:
- ''
- - '#!/bin/bash -xe
'
- 'yum update -y aws-cfn-bootstrap
'
- '/opt/aws/bin/cfn-init -v '
- ' --stack '
- Ref: AWS::StackName
- ' --resource LocustServer '
- ' --configsets install_all '
- ' --region '
- Ref: AWS::Region
- '
'
- '# Get the sample Locust files
'
- 'mkdir -p /home/ec2-user/locust
'
- 'wget https://raw.githubusercontent.com/concurrencylabs/locust-cloudwatch/master/locustfile.py -O /home/ec2-user/locust/locustfile.py
'
- 'wget https://raw.githubusercontent.com/concurrencylabs/locust-cloudwatch/master/locust_cw.py -O /home/ec2-user/locust/locust_cw.py
'
- 'wget https://raw.githubusercontent.com/concurrencylabs/locust-cloudwatch/master/requirements.txt -O /home/ec2-user/locust/requirements.txt
'
- 'chown ec2-user:ec2-user /home/ec2-user/locust
'
- 'chown ec2-user:ec2-user /home/ec2-user/locust/locustfile.py
'
- 'chown ec2-user:ec2-user /home/ec2-user/locust/locust_cw.py
'
- 'chown ec2-user:ec2-user /home/ec2-user/locust/requirements.txt
'
- '/opt/aws/bin/cfn-signal -e $? '
- ' --stack '
- Ref: AWS::StackName
- ' --resource LocustServer '
- ' --region '
- Ref: AWS::Region
- '
'
Type: AWS::EC2::Instance
LocustServerSecurityGroup:
Properties:
GroupDescription: Enable HTTP access via port 8089 and SSH access via port 22
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: '80'
IpProtocol: tcp
ToPort: '8089'
- CidrIp: 0.0.0.0/0
FromPort: '22'
IpProtocol: tcp
ToPort: '22'
Type: AWS::EC2::SecurityGroup
LogRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Version: '2012-10-17'
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- logs:Create*
- logs:Describe*
- logs:PutLogEvents
Effect: Allow
Resource:
- arn:aws:logs:*:*:*
- Action:
- cloudwatch:PutMetricData*
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
PolicyName: LocustCwConnectorRolePolicy
Type: AWS::IAM::Role
LocustCWConnectorInstanceProfile:
Properties:
Path: /
Roles:
- Ref: LogRole
Type: AWS::IAM::InstanceProfile