-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.yml
126 lines (123 loc) · 3.8 KB
/
ecs.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
AWSTemplateFormatVersion: "2010-09-09"
Description: ECS for crowley.cloud
Resources:
WebListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
ListenerArn:
Fn::ImportValue: crowley-cloud-loadbalancer-LoadBalancerListener
Priority: 100
Conditions:
- Field: path-pattern
Values:
- /*
Actions:
- TargetGroupArn: !Ref WebTargetGroup
Type: forward
WebTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
VpcId:
Fn::ImportValue: crowley-cloud-networking-VPC
Port: 80
Protocol: HTTP
Matcher:
HttpCode: 200-299
TargetType: ip
HealthCheckIntervalSeconds: 10
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
HealthCheckPath: /
HealthCheckProtocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: "60"
CrowleyCloudECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: CrowleyCloudECSCluster
CrowleyCloudECSService:
Type: AWS::ECS::Service
DependsOn: WebListenerRule
Properties:
Cluster: !Ref CrowleyCloudECSCluster
DesiredCount: 1
LaunchType: FARGATE
LoadBalancers:
- ContainerName: crowley-cloud
ContainerPort: 80
TargetGroupArn: !Ref WebTargetGroup
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
Subnets:
- Fn::ImportValue: crowley-cloud-networking-PrivateSubnetA
- Fn::ImportValue: crowley-cloud-networking-PrivateSubnetB
SecurityGroups:
- !Ref ContainerSecurityGroup
ServiceName: crowley-cloud-service
TaskDefinition: !Ref CrowleyCloudTaskDefinition
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 50
ContainerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId:
Fn::ImportValue: crowley-cloud-networking-VPC
GroupDescription: Container security group for ecs containers
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
IpProtocol: -1
ECSTaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ecs-tasks.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
Policies:
- PolicyName: AWSTrainingAmazonECSTaskExecutionRolePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
# ECS Tasks to download images from ECR
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'
# ECS tasks to upload logs to CloudWatch
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
CloudWatchLogsGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/ecs/crowleycloud
RetentionInDays: 7
CrowleyCloudTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: "256"
Memory: "512"
ExecutionRoleArn: !Ref ECSTaskRole
Family: crowley-cloud
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ContainerDefinitions:
-
Name: crowley-cloud
Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/crowley-cloud-ecr:latest"
PortMappings:
- ContainerPort: 80
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref CloudWatchLogsGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: crowleycloud