Skip to content

Commit b212e31

Browse files
ECS infrastructure (#76)
* add infra template * add task definitions
1 parent 2eea335 commit b212e31

File tree

4 files changed

+1288
-0
lines changed

4 files changed

+1288
-0
lines changed

ecs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Description
2+
3+
This directory holds the infrastrucutre templates to run Storedog on AWS ECS via EC2. EC2 is the preferred hosting engine due to the `bridge` network mode, which is not available in Fargate. This allows our containers to inter-communicate.
4+
5+
The memory and CPU settings defined in the `storedog-task-definition.json` assume you are running at least one `m3.xlarge` instance. Note that these settings have not yet been optimized so there is an opportunity to downsize.

ecs/ecs-cluster.json

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Description": "The template used to create an ECS Cluster from the ECS Console.",
4+
"Parameters": {
5+
"ECSClusterName": {
6+
"Type": "String",
7+
"Description": "Specifies the ECS Cluster Name with which the resources would be associated",
8+
"Default": "Storedog-Cluster"
9+
},
10+
"SecurityGroupIds": {
11+
"Type": "CommaDelimitedList",
12+
"Description": "Optional - Specifies the Comma separated list of the Security Group Id of an existing Security Group.",
13+
"Default": ""
14+
},
15+
"VpcId": {
16+
"Type": "String",
17+
"Description": "Optional - Specifies the ID of an existing VPC in which to launch your container instances. If you specify a VPC ID, you must specify a list of existing subnets in that VPC. If you do not specify a VPC ID, a new VPC is created with at least 1 subnet.",
18+
"Default": "",
19+
"AllowedPattern": "^(?:vpc-[0-9a-f]{8,17}|)$",
20+
"ConstraintDescription": "VPC Id must begin with 'vpc-' and have a valid uuid"
21+
},
22+
"SubnetIds": {
23+
"Type": "CommaDelimitedList",
24+
"Description": "Optional - Specifies the Comma separated list of existing VPC Subnet Ids where ECS instances will run",
25+
"Default": ""
26+
},
27+
"LatestECSOptimizedAMI": {
28+
"Description": "AMI ID",
29+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
30+
"Default": "/aws/service/ecs/optimized-ami/amazon-linux-2/kernel-5.10/recommended/image_id"
31+
},
32+
"IamRoleInstanceProfile": {
33+
"Type": "String",
34+
"Description": "Specifies the Name or the Amazon Resource Name (ARN) of the instance profile associated with the IAM role for the instance",
35+
"Default": ""
36+
}
37+
},
38+
"Resources": {
39+
"ECSLaunchTemplate": {
40+
"Type": "AWS::EC2::LaunchTemplate",
41+
"DependsOn": "ECSCluster",
42+
"Properties": {
43+
"LaunchTemplateData": {
44+
"ImageId": {
45+
"Ref": "LatestECSOptimizedAMI"
46+
},
47+
"SecurityGroupIds": {
48+
"Ref": "SecurityGroupIds"
49+
},
50+
"InstanceType": "m3.xlarge",
51+
"IamInstanceProfile": {
52+
"Arn": {
53+
"Ref": "IamRoleInstanceProfile"
54+
}
55+
},
56+
"UserData": {
57+
"Fn::Base64": {
58+
"Fn::Sub": [
59+
"#!/bin/bash \necho ECS_CLUSTER=${ClusterName} >> /etc/ecs/ecs.config;",
60+
{
61+
"ClusterName": {
62+
"Ref": "ECSClusterName"
63+
}
64+
}
65+
]
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"ECSAutoScalingGroup": {
72+
"Type": "AWS::AutoScaling::AutoScalingGroup",
73+
"DependsOn": "ECSCluster",
74+
"Properties": {
75+
"MinSize": 0,
76+
"MaxSize": "2",
77+
"DesiredCapacity": 0,
78+
"LaunchTemplate": {
79+
"LaunchTemplateId": {
80+
"Ref": "ECSLaunchTemplate"
81+
},
82+
"Version": {
83+
"Fn::GetAtt": [
84+
"ECSLaunchTemplate",
85+
"LatestVersionNumber"
86+
]
87+
}
88+
},
89+
"VPCZoneIdentifier": {
90+
"Ref": "SubnetIds"
91+
},
92+
"Tags": [
93+
{
94+
"Key": "Name",
95+
"PropagateAtLaunch": true,
96+
"Value": {
97+
"Fn::Join": [
98+
" - ",
99+
[
100+
"ECS Instance",
101+
{
102+
"Ref": "ECSClusterName"
103+
}
104+
]
105+
]
106+
}
107+
}
108+
]
109+
}
110+
},
111+
"ECSCluster": {
112+
"Type": "AWS::ECS::Cluster",
113+
"Properties": {
114+
"ClusterName": {
115+
"Ref": "ECSClusterName"
116+
},
117+
"ClusterSettings": [
118+
{
119+
"Name": "containerInsights",
120+
"Value": "disabled"
121+
}
122+
],
123+
"Configuration": {
124+
"ExecuteCommandConfiguration": {
125+
"Logging": "DEFAULT"
126+
}
127+
},
128+
"ServiceConnectDefaults": {
129+
"Namespace": "Storedog-Cluster"
130+
},
131+
"Tags": []
132+
}
133+
},
134+
"EC2CapacityProvider": {
135+
"Type": "AWS::ECS::CapacityProvider",
136+
"Properties": {
137+
"AutoScalingGroupProvider": {
138+
"AutoScalingGroupArn": {
139+
"Ref": "ECSAutoScalingGroup"
140+
},
141+
"ManagedScaling": {
142+
"Status": "ENABLED",
143+
"TargetCapacity": 100
144+
},
145+
"ManagedTerminationProtection": "DISABLED"
146+
}
147+
}
148+
},
149+
"ClusterCPAssociation": {
150+
"Type": "AWS::ECS::ClusterCapacityProviderAssociations",
151+
"DependsOn": "ECSCluster",
152+
"Properties": {
153+
"Cluster": {
154+
"Ref": "ECSClusterName"
155+
},
156+
"CapacityProviders": [
157+
{
158+
"Ref": "EC2CapacityProvider"
159+
}
160+
],
161+
"DefaultCapacityProviderStrategy": [
162+
{
163+
"Base": 0,
164+
"Weight": 1,
165+
"CapacityProvider": {
166+
"Ref": "EC2CapacityProvider"
167+
}
168+
}
169+
]
170+
}
171+
}
172+
},
173+
"Outputs": {
174+
"ECSCluster": {
175+
"Description": "The created cluster.",
176+
"Value": {
177+
"Ref": "ECSCluster"
178+
}
179+
}
180+
}
181+
}

0 commit comments

Comments
 (0)