forked from lambci/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.spot.template
170 lines (166 loc) · 5.38 KB
/
cluster.spot.template
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "LambCI build servers running on ECS",
"Parameters": {
"InstanceType": {
"Description": "EC2 instance type (t2.micro, t2.medium, t2.large, etc)",
"Type": "String",
"Default": "t2.micro",
"ConstraintDescription": "must be a valid EC2 instance type."
},
"SpotPrice" : {
"Type" : Number,
"Description" : "Spot Price based on your EC2 type",
},
"VpcId" : {
"Type" : "AWS::EC2::VPC::Id",
"Description" : "VpcId of your existing Virtual Private Cloud (VPC)",
"ConstraintDescription" : "must be the VPC Id of an existing Virtual Private Cloud."
},
"Subnets" : {
"Type" : "List<AWS::EC2::Subnet::Id>",
"Description" : "The list of SubnetIds in your Virtual Private Cloud (VPC)",
"ConstraintDescription" : "must be a list of an existing subnets in the selected Virtual Private Cloud."
},
"AZs" : {
"Type" : "List<AWS::EC2::AvailabilityZone::Name>",
"Description" : "The list of AvailabilityZones for your Virtual Private Cloud (VPC)",
"ConstraintDescription" : "must be a list if valid EC2 availability zones for the selected Virtual Private Cloud"
}
},
"Mappings": {
"EcsAmisByRegion": {
"us-east-1": {"ami": "ami-a88a46c5"},
"us-west-1": {"ami": "ami-34a7e354"},
"us-west-2": {"ami": "ami-ae0acdce"},
"eu-west-1": {"ami": "ami-ccd942bf"},
"eu-central-1": {"ami": "ami-4a5eb625"},
"ap-northeast-1": {"ami": "ami-4aab5d2b"},
"ap-southeast-1": {"ami": "ami-24c71547"},
"ap-southeast-2": {"ami": "ami-0bf2da68"}
}
},
"Resources": {
"Cluster": {
"Type": "AWS::ECS::Cluster"
},
"BuildTask": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [{
"Name": "build",
"Image": "lambci/ecs",
"Memory": 450,
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {"Ref": "EcsLogs"},
"awslogs-region": {"Ref": "AWS::Region"}
}
},
"Environment": [{"Name": "LOG_GROUP", "Value": {"Ref": "EcsLogs"}}],
"MountPoints": [{"SourceVolume": "docker-socket", "ContainerPath": "/var/run/docker.sock"}]
}],
"Volumes": [{"Name": "docker-socket", "Host": {"SourcePath": "/var/run/docker.sock"}}]
}
},
"EcsLogs": {
"Type": "AWS::Logs::LogGroup"
},
"AutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {"Ref": "AZs"},
"VPCZoneIdentifier" : { "Ref" : "Subnets" },
"LaunchConfigurationName": {"Ref": "LaunchConfig"},
"DesiredCapacity": "1",
"MinSize": "0",
"MaxSize": "4"
},
"CreationPolicy": {
"ResourceSignal": {
"Count": "1"
}
}
},
"LaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"AssociatePublicIpAddress" : "true",
"SpotPrice": { "Ref" : "SpotPrice" },
"ImageId": {"Fn::FindInMap": ["EcsAmisByRegion", {"Ref": "AWS::Region"}, "ami"]},
"IamInstanceProfile": {"Ref": "InstanceProfile"},
"InstanceType": {"Ref": "InstanceType"},
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"UserData": {
"Fn::Base64": {
"Fn::Join": ["", [
"#!/bin/bash\n",
"echo ECS_CLUSTER=", {"Ref": "Cluster"}, " >> /etc/ecs/ecs.config\n",
"yum install -y aws-cfn-bootstrap\n",
"/opt/aws/bin/cfn-signal -e $? --resource AutoScalingGroup --stack ", {"Ref": "AWS::StackName"}, " --region ", {"Ref": "AWS::Region"}
]]
}
}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable HTTP access and SSH access",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" : [
{ "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" }
]
}
},
"InstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [{"Ref": "InstanceRole"}]
}
},
"InstanceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": {
"Effect": "Allow",
"Principal": {"Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
},
"Policies": [{
"PolicyName": "RunEcs",
"PolicyDocument": {
"Statement": {
"Effect": "Allow",
"Action": [
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:Submit*"
],
"Resource": "*"
}
}
},{
"PolicyName": "WriteLogs",
"PolicyDocument": {
"Statement": {
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
}
}]
}
}
}
}