Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit f78929c

Browse files
committed
Refactored CloudFormation templates to use nested stacks
1 parent 029bf7e commit f78929c

File tree

5 files changed

+376
-0
lines changed

5 files changed

+376
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ Once logged in, you can build the image running docker build from the root folde
7878
docker build -t your_docker_hub_user/dlt-fargate .
7979
```
8080

81+
Test your docker container locally to verify it runs correctly:
82+
83+
```bash
84+
docker run -it dlt-fargate taurus.yml
85+
```
86+
8187
Now you can push the image to the registry
8288

8389
```bash

cloudformation/additional-region.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: >
17+
Master Template of Distributed Load Test Using AWS Fargate.
18+
It deploys an ECR Repository, an ECS Fargate Cluster, a VPC,
19+
CloudWatch Logs group for the Fargate tasks and associated
20+
IAM roles.
21+
22+
Parameters:
23+
DockerRegistry:
24+
Type: String
25+
Description: >
26+
ECR Registry created in the master CloudFormation template. It should be in the form of
27+
account_id.dkr.ecr.region.amazonaws.com/repository_name
28+
TaskExecutionRoleArn:
29+
Type: String
30+
Description: >
31+
IAM Execution Role ARN for the Fargate tasks, it should have been created by the master
32+
CloudFormation template and available in the Outputs section.
33+
34+
Resources:
35+
Vpc:
36+
Type: AWS::CloudFormation::Stack
37+
Properties:
38+
TemplateURL: "https://s3.amazonaws.com/load-testing-using-aws-fargate/artifacts/templates/fargate-vpc.yaml"
39+
40+
FargateCluster:
41+
Type: AWS::CloudFormation::Stack
42+
DependsOn: Vpc
43+
Properties:
44+
TemplateURL: "https://s3.amazonaws.com/load-testing-using-aws-fargate/artifacts/templates/fargate-cluster.yaml"
45+
Parameters:
46+
VpcId: !GetAtt Vpc.Outputs.VpcId
47+
TaskExecutionRoleArn: !Ref TaskExecutionRoleArn
48+
DockerImage: !Join
49+
- ''
50+
- - !Ref DockerRegistry
51+
- ':latest'

cloudformation/fargate-cluster.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: >
17+
Distributed load testing (DLT) using AWS Fargate.
18+
Creates a Fargate Cluster, a Task Definition, IAM Role and a CloudWatch Log Group
19+
20+
Parameters:
21+
VpcId:
22+
Type: String
23+
DockerImage:
24+
Type: String
25+
TaskExecutionRoleArn:
26+
Type: String
27+
DockerTaskMemory:
28+
Type: Number
29+
Default: 2048
30+
AllowedValues:
31+
- 512
32+
- 1024
33+
- 2048
34+
- 3072
35+
- 4096
36+
- 5120
37+
- 6144
38+
- 7168
39+
- 8192
40+
- 16384
41+
DockerTaskCpu:
42+
Type: Number
43+
Default: 512
44+
AllowedValues:
45+
- 256
46+
- 512
47+
- 1024
48+
- 2048
49+
- 4096
50+
51+
Resources:
52+
Cluster:
53+
Type: AWS::ECS::Cluster
54+
55+
FargateTaskSecurityGroup:
56+
Type: AWS::EC2::SecurityGroup
57+
Properties:
58+
GroupDescription: 'DLT Fargate tasks security group'
59+
VpcId: !Ref VpcId
60+
SecurityGroupEgress:
61+
IpProtocol: '-1'
62+
CidrIp: 0.0.0.0/0
63+
64+
FargateTaskCloudWatchLogGroup:
65+
Type: AWS::Logs::LogGroup
66+
Properties:
67+
RetentionInDays: 365
68+
69+
TaurusLogFilterAvgResponseTime:
70+
Type: AWS::Logs::MetricFilter
71+
Properties:
72+
FilterPattern: "[time, logType=INFO*, logTitle=Current*, numVu, vu, numSucc, succ, numFail, fail, avgRt, x]"
73+
LogGroupName: !Ref FargateTaskCloudWatchLogGroup
74+
MetricTransformations:
75+
-
76+
MetricValue: "$avgRt"
77+
MetricNamespace: "dlt-fargate/``````taurus``````"
78+
MetricName: "avgResponseTime"
79+
80+
FargateTaskDefinition:
81+
Type: AWS::ECS::TaskDefinition
82+
Properties:
83+
Cpu: !Ref DockerTaskCpu
84+
ExecutionRoleArn: !Ref TaskExecutionRoleArn
85+
Memory: !Ref DockerTaskMemory
86+
NetworkMode: awsvpc
87+
RequiresCompatibilities:
88+
- FARGATE
89+
TaskRoleArn: !Ref TaskExecutionRoleArn
90+
ContainerDefinitions:
91+
-
92+
Name: "dlt-fargate-task"
93+
Essential: true
94+
Image: !Ref DockerImage
95+
Memory: !Ref DockerTaskMemory
96+
LogConfiguration:
97+
LogDriver: awslogs
98+
Options:
99+
awslogs-group: !Ref FargateTaskCloudWatchLogGroup
100+
awslogs-region: !Ref "AWS::Region"
101+
awslogs-stream-prefix: "dlt-fargate"
102+
Command:
103+
- "taurus.yml"
104+
105+
106+
Outputs:
107+
FargateClusterName:
108+
Value: !Ref Cluster
109+
TaskSecurityGroup:
110+
Value: !Ref FargateTaskSecurityGroup
111+
TaskDefinitionArn:
112+
Value: !Ref FargateTaskDefinition

cloudformation/fargate-vpc.yaml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: >
17+
Distributed Load Testing using AWS Fargate.
18+
Dedicated VPC where the ECS Fargate tasks will be placed
19+
20+
Parameters:
21+
VpcCidrBlock:
22+
Type: String
23+
Default: 192.168.0.0/16
24+
Description: CIDR block of the new VPC where Fargate will be placed
25+
SubnetACidrBlock:
26+
Type: String
27+
Default: 192.168.0.0/20
28+
Description: CIDR block of subnet A
29+
SubnetBCidrBlock:
30+
Type: String
31+
Default: 192.168.16.0/20
32+
Description: CIDR block of subnet B
33+
SubnetCCidrBlock:
34+
Type: String
35+
Default: 192.168.32.0/20
36+
Description: CIDR block of subnet C
37+
38+
Mappings:
39+
RegionMap:
40+
us-east-1:
41+
az1: us-east-1a
42+
az2: us-east-1b
43+
az3: us-east-1c
44+
us-east-2:
45+
az1: us-east-2a
46+
az2: us-east-2b
47+
az3: us-east-2c
48+
us-west-2:
49+
az1: us-west-2a
50+
az2: us-west-2b
51+
az3: us-west-2c
52+
53+
Resources:
54+
DLTVpc:
55+
Type: AWS::EC2::VPC
56+
Properties:
57+
CidrBlock: !Ref VpcCidrBlock
58+
InstanceTenancy: default
59+
EnableDnsSupport: true
60+
EnableDnsHostnames: true
61+
Tags:
62+
- Key: Name
63+
Value: dlt-fargate
64+
65+
PublicSubnetA:
66+
Type: AWS::EC2::Subnet
67+
Properties:
68+
CidrBlock: !Ref SubnetACidrBlock
69+
AvailabilityZone: !FindInMap [RegionMap, !Ref "AWS::Region", "az1"]
70+
VpcId: !Ref DLTVpc
71+
72+
PublicSubnetB:
73+
Type: AWS::EC2::Subnet
74+
Properties:
75+
CidrBlock: !Ref SubnetBCidrBlock
76+
AvailabilityZone: !FindInMap [RegionMap, !Ref "AWS::Region", "az2"]
77+
VpcId: !Ref DLTVpc
78+
79+
PublicSubnetC:
80+
Type: AWS::EC2::Subnet
81+
Properties:
82+
CidrBlock: !Ref SubnetCCidrBlock
83+
AvailabilityZone: !FindInMap [RegionMap, !Ref "AWS::Region", "az3"]
84+
VpcId: !Ref DLTVpc
85+
86+
InternetGateway:
87+
Type: AWS::EC2::InternetGateway
88+
Properties: {}
89+
90+
MainRouteTable:
91+
Type: AWS::EC2::RouteTable
92+
Properties:
93+
VpcId: !Ref DLTVpc
94+
95+
GatewayAttachment:
96+
Type: AWS::EC2::VPCGatewayAttachment
97+
Properties:
98+
VpcId: !Ref DLTVpc
99+
InternetGatewayId: !Ref InternetGateway
100+
101+
RouteToInternet:
102+
Type: AWS::EC2::Route
103+
DependsOn: GatewayAttachment
104+
Properties:
105+
DestinationCidrBlock: 0.0.0.0/0
106+
RouteTableId: !Ref MainRouteTable
107+
GatewayId: !Ref InternetGateway
108+
109+
RouteTableAssociationA:
110+
Type: AWS::EC2::SubnetRouteTableAssociation
111+
Properties:
112+
RouteTableId: !Ref MainRouteTable
113+
SubnetId: !Ref PublicSubnetA
114+
115+
RouteTableAssociationB:
116+
Type: AWS::EC2::SubnetRouteTableAssociation
117+
Properties:
118+
RouteTableId: !Ref MainRouteTable
119+
SubnetId: !Ref PublicSubnetB
120+
121+
RouteTableAssociationC:
122+
Type: AWS::EC2::SubnetRouteTableAssociation
123+
Properties:
124+
RouteTableId: !Ref MainRouteTable
125+
SubnetId: !Ref PublicSubnetC
126+
127+
128+
Outputs:
129+
VpcId:
130+
Value: !Ref DLTVpc
131+
SubnetA:
132+
Value: !Ref PublicSubnetA
133+
SubnetB:
134+
Value: !Ref PublicSubnetB
135+
SubnetC:
136+
Value: !Ref PublicSubnetC

cloudformation/master.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
# software and associated documentation files (the "Software"), to deal in the Software
5+
# without restriction, including without limitation the rights to use, copy, modify,
6+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
# permit persons to whom the Software is furnished to do so.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
AWSTemplateFormatVersion: 2010-09-09
16+
Description: >
17+
Master Template of Distributed Load Test Using AWS Fargate.
18+
It deploys an ECR Repository, an ECS Fargate Cluster, a VPC,
19+
CloudWatch Logs group for the Fargate tasks and associated
20+
IAM roles.
21+
22+
Resources:
23+
DockerRegistry:
24+
Type: AWS::ECR::Repository
25+
26+
TaskExecutionRole:
27+
Type: AWS::IAM::Role
28+
Properties:
29+
AssumeRolePolicyDocument:
30+
Version: "2012-10-17"
31+
Statement:
32+
- Effect: Allow
33+
Action: "sts:AssumeRole"
34+
Principal:
35+
Service: "ecs-tasks.amazonaws.com"
36+
ManagedPolicyArns:
37+
- "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
38+
39+
Vpc:
40+
Type: AWS::CloudFormation::Stack
41+
Properties:
42+
TemplateURL: "https://s3.amazonaws.com/load-testing-using-aws-fargate/artifacts/templates/fargate-vpc.yaml"
43+
44+
FargateCluster:
45+
Type: AWS::CloudFormation::Stack
46+
DependsOn: Vpc
47+
Properties:
48+
TemplateURL: "https://s3.amazonaws.com/load-testing-using-aws-fargate/artifacts/templates/fargate-cluster.yaml"
49+
Parameters:
50+
VpcId: !GetAtt Vpc.Outputs.VpcId
51+
TaskExecutionRoleArn: !GetAtt TaskExecutionRole.Arn
52+
DockerImage: !Join
53+
- ''
54+
- - !Ref 'AWS::AccountId'
55+
- '.dkr.ecr.'
56+
- !Ref 'AWS::Region'
57+
- '.amazonaws.com/'
58+
- !Ref DockerRegistry
59+
- ':latest'
60+
61+
Outputs:
62+
TaskExecutionRoleArn:
63+
Value: !GetAtt TaskExecutionRole.Arn
64+
DockerRegistry:
65+
Value: !Join
66+
- ''
67+
- - !Ref 'AWS::AccountId'
68+
- '.dkr.ecr.'
69+
- !Ref 'AWS::Region'
70+
- '.amazonaws.com/'
71+
- !Ref DockerRegistry

0 commit comments

Comments
 (0)