-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcwagent-ecs-instance-metric-cfn.yaml
executable file
·156 lines (156 loc) · 4.55 KB
/
cwagent-ecs-instance-metric-cfn.yaml
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
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
ClusterName:
Type: String
Description: Enter the name of your ECS cluster from which you want to collect
metrics
CreateIAMRoles:
Type: String
Default: 'False'
AllowedValues:
- 'True'
- 'False'
Description: Whether to create default IAM roles
ConstraintDescription: must specify True or False.
TaskRoleArn:
Type: String
Default: Default
Description: Enter the role arn you want to use as the ecs task role
ExecutionRoleArn:
Type: String
Default: Default
Description: Enter the role arn you want to use as the ecs execution role
Conditions:
CreateRoles:
Fn::Equals:
- Ref: CreateIAMRoles
- 'True'
DefaultTaskRole:
Fn::Equals:
- Ref: TaskRoleArn
- Default
DefaultExecutionRole:
Fn::Equals:
- Ref: ExecutionRoleArn
- Default
Resources:
ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: ecs-cwagent-daemon-service
TaskRoleArn:
Fn::If:
- CreateRoles
- Fn::GetAtt:
- ECSTaskRole
- Arn
- Fn::If:
- DefaultTaskRole
- Fn::Sub: arn:aws:iam::${AWS::AccountId}:role/CWAgentECSTaskRole
- Ref: TaskRoleArn
ExecutionRoleArn:
Fn::If:
- CreateRoles
- Fn::GetAtt:
- ECSExecutionRole
- Arn
- Fn::If:
- DefaultExecutionRole
- Fn::Sub: arn:aws:iam::${AWS::AccountId}:role/CWAgentECSExecutionRole
- Ref: ExecutionRoleArn
NetworkMode: bridge
ContainerDefinitions:
- Name: cloudwatch-agent
Image: amazon/cloudwatch-agent:latest
MountPoints:
- ReadOnly: true
ContainerPath: "/rootfs/proc"
SourceVolume: proc
- ReadOnly: true
ContainerPath: "/rootfs/dev"
SourceVolume: dev
- ReadOnly: true
ContainerPath: "/sys/fs/cgroup"
SourceVolume: al2_cgroup
- ReadOnly: true
ContainerPath: "/cgroup"
SourceVolume: al1_cgroup
- ReadOnly: true
ContainerPath: "/rootfs/sys/fs/cgroup"
SourceVolume: al2_cgroup
- ReadOnly: true
ContainerPath: "/rootfs/cgroup"
SourceVolume: al1_cgroup
Environment:
- Name: CW_CONFIG_CONTENT
Value: 'ecs-cwagent-daemon-service'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-create-group: 'True'
awslogs-group: "/ecs/ecs-cwagent-daemon-service"
awslogs-region:
Ref: AWS::Region
awslogs-stream-prefix: ecs
RequiresCompatibilities:
- EC2
Volumes:
- Name: proc
Host:
SourcePath: "/proc"
- Name: dev
Host:
SourcePath: "/dev"
- Name: al1_cgroup
Host:
SourcePath: "/cgroup"
- Name: al2_cgroup
Host:
SourcePath: "/sys/fs/cgroup"
Cpu: '128'
Memory: '64'
ECSDaemonService:
Type: AWS::ECS::Service
Properties:
TaskDefinition:
Ref: ECSTaskDefinition
Cluster:
Ref: ClusterName
LaunchType: EC2
SchedulingStrategy: DAEMON
ServiceName: cwagent-daemon-service
ECSTaskRole:
Type: AWS::IAM::Role
Condition: CreateRoles
Properties:
Description: Allows ECS tasks to call AWS services on your behalf.
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
RoleName: CWAgentECSTaskRole
ECSExecutionRole:
Type: AWS::IAM::Role
Condition: CreateRoles
Properties:
Description: Allows ECS container agent makes calls to the Amazon ECS API on
your behalf.
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
RoleName: CWAgentECSExecutionRole