-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfn.yml
174 lines (164 loc) · 5.05 KB
/
cfn.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
AWSTemplateFormatVersion: '2010-09-09'
Description: ECS Fargate with XRAY implementation
Parameters:
ServiceName:
Type: String
Default: xray-test
Description: A name for the service
Subnet:
Type: String
Default: subnet-9a2902ee
Description: "subnet-id"
Resources:
ECSTaskExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument: # The Trust Relationship
Statement:
- Effect: Allow
Principal:
Service: [ecs-tasks.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
Policies:
- PolicyName: AmazonECSTaskExecutionRolePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
# Allow the ECS Tasks to download images from ECR
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'
# Allow the ECS tasks to upload logs to CloudWatch
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
# xray
- 'xray:PutTraceSegments'
- 'xray:PutTelemetryRecords'
- 'xray:GetSamplingRules'
- 'xray:GetSamplingTargets'
- 'xray:GetSamplingStatisticSummaries'
# sqs
- 'sqs:*'
Resource: '*'
ECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Sub ${ServiceName}
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref 'ServiceName'
Memory: 1024
Cpu: 512
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !GetAtt ECSTaskExecutionRole.Arn
TaskRoleArn: !GetAtt ECSTaskExecutionRole.Arn
ContainerDefinitions:
- Name: "app"
DependsOn:
- Condition: START
ContainerName: "mysql"
- Condition: START
ContainerName: "xray-daemon"
Image: !Join
- '.'
- - !Ref 'AWS::AccountId'
- "dkr.ecr"
- !Ref 'AWS::Region'
- "amazonaws.com/xray-app"
Environment:
- Name: "ENVIRONMENT"
Value: "production"
- Name: "XRAY_APP_NAME"
Value: "cloud-xray-test"
- Name: "XRAY_DAEMON_ADDR"
Value: "localhost:2000"
- Name: "MYSQL_ADDR"
Value: "localhost"
- Name: "SQS_QUEUE_URL"
Value: !Ref MySQS
LogConfiguration:
LogDriver: 'awslogs'
Options:
awslogs-group: !Sub /ecs/${ServiceName}
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: !Ref 'ServiceName'
- Name: "mysql"
Image: !Join
- '.'
- - !Ref 'AWS::AccountId'
- "dkr.ecr"
- !Ref 'AWS::Region'
- "amazonaws.com/xray-mariadb:10.5.3"
Environment:
- Name: "MYSQL_ROOT_PASSWORD"
Value: "root"
- Name: "MYSQL_DATABASE"
Value: "xray"
PortMappings:
- ContainerPort: 3306
Protocol: tcp
LogConfiguration:
LogDriver: 'awslogs'
Options:
awslogs-group: !Sub /ecs/${ServiceName}
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: !Ref 'ServiceName'
- Name: "xray-daemon"
Memory: 256
Cpu: 32
Image: !Join
- '.'
- - !Ref 'AWS::AccountId'
- "dkr.ecr"
- !Ref 'AWS::Region'
- "amazonaws.com/aws-xray-daemon"
PortMappings:
- ContainerPort: 2000
Protocol: udp
LogConfiguration:
LogDriver: 'awslogs'
Options:
awslogs-group: !Sub /ecs/${ServiceName}
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: !Ref 'ServiceName'
Service:
Type: AWS::ECS::Service
Properties:
ServiceName: !Ref 'ServiceName'
Cluster: !Ref 'ECSCluster'
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 0
DesiredCount: 1
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !GetAtt 'ContainerSecurityGroup.GroupId'
Subnets:
- !Ref 'Subnet'
TaskDefinition: !Ref 'TaskDefinition'
ContainerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Access to the Fargate containers
SecurityGroupIngress:
- IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /ecs/${ServiceName}
MySQS:
Type: AWS::SQS::Queue
Properties:
QueueName: !Ref ServiceName