awslabs.cloudwatch-applicationsignals-mcp-server 0.1.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awslabs/__init__.py +17 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/__init__.py +17 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/audit_presentation_utils.py +288 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/audit_utils.py +912 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/aws_clients.py +120 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/canary_utils.py +910 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-dotnet-enablement.md +435 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-java-enablement.md +321 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-nodejs-enablement.md +420 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-python-enablement.md +598 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-dotnet-enablement.md +264 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-java-enablement.md +193 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-nodejs-enablement.md +198 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-python-enablement.md +236 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-dotnet-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-java-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-nodejs-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-python-enablement.md +169 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-dotnet-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-java-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-nodejs-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-python-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_tools.py +147 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/server.py +1505 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/service_audit_utils.py +231 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/service_tools.py +659 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/sli_report_client.py +333 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/slo_tools.py +386 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/trace_tools.py +784 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/utils.py +172 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/METADATA +808 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/RECORD +36 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/WHEEL +4 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/entry_points.txt +2 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/LICENSE +174 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/NOTICE +2 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for Python on AWS Lambda
|
|
2
|
+
|
|
3
|
+
Your task is to modify Infrastructure as Code (IaC) files to enable AWS Application Signals for Python Lambda functions. You will:
|
|
4
|
+
|
|
5
|
+
1. Add IAM permissions for Application Signals
|
|
6
|
+
2. Configure X-Ray tracing
|
|
7
|
+
3. Add the ADOT Lambda layer
|
|
8
|
+
4. Set the required environment variables.
|
|
9
|
+
|
|
10
|
+
If you cannot determine a value (such as AWS Region): Ask the user for clarification before proceeding. Do not guess or make up values.
|
|
11
|
+
|
|
12
|
+
## Region-Specific Layer ARNs
|
|
13
|
+
|
|
14
|
+
Select the correct ARN for your region:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"af-south-1": "arn:aws:lambda:af-south-1:904233096616:layer:AWSOpenTelemetryDistroPython:13",
|
|
19
|
+
"ap-east-1": "arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroPython:13",
|
|
20
|
+
"ap-northeast-1": "arn:aws:lambda:ap-northeast-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
21
|
+
"ap-northeast-2": "arn:aws:lambda:ap-northeast-2:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
22
|
+
"ap-northeast-3": "arn:aws:lambda:ap-northeast-3:615299751070:layer:AWSOpenTelemetryDistroPython:15",
|
|
23
|
+
"ap-south-1": "arn:aws:lambda:ap-south-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
24
|
+
"ap-south-2": "arn:aws:lambda:ap-south-2:796973505492:layer:AWSOpenTelemetryDistroPython:13",
|
|
25
|
+
"ap-southeast-1": "arn:aws:lambda:ap-southeast-1:615299751070:layer:AWSOpenTelemetryDistroPython:15",
|
|
26
|
+
"ap-southeast-2": "arn:aws:lambda:ap-southeast-2:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
27
|
+
"ap-southeast-3": "arn:aws:lambda:ap-southeast-3:039612877180:layer:AWSOpenTelemetryDistroPython:13",
|
|
28
|
+
"ap-southeast-4": "arn:aws:lambda:ap-southeast-4:713881805771:layer:AWSOpenTelemetryDistroPython:13",
|
|
29
|
+
"ap-southeast-5": "arn:aws:lambda:ap-southeast-5:152034782359:layer:AWSOpenTelemetryDistroPython:4",
|
|
30
|
+
"ap-southeast-7": "arn:aws:lambda:ap-southeast-7:980416031188:layer:AWSOpenTelemetryDistroPython:4",
|
|
31
|
+
"ca-central-1": "arn:aws:lambda:ca-central-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
32
|
+
"ca-west-1": "arn:aws:lambda:ca-west-1:595944127152:layer:AWSOpenTelemetryDistroPython:4",
|
|
33
|
+
"cn-north-1": "arn:aws-cn:lambda:cn-north-1:440179912924:layer:AWSOpenTelemetryDistroPython:4",
|
|
34
|
+
"cn-northwest-1": "arn:aws-cn:lambda:cn-northwest-1:440180067931:layer:AWSOpenTelemetryDistroPython:4",
|
|
35
|
+
"eu-central-1": "arn:aws:lambda:eu-central-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
36
|
+
"eu-central-2": "arn:aws:lambda:eu-central-2:156041407956:layer:AWSOpenTelemetryDistroPython:13",
|
|
37
|
+
"eu-north-1": "arn:aws:lambda:eu-north-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
38
|
+
"eu-south-1": "arn:aws:lambda:eu-south-1:257394471194:layer:AWSOpenTelemetryDistroPython:13",
|
|
39
|
+
"eu-south-2": "arn:aws:lambda:eu-south-2:490004653786:layer:AWSOpenTelemetryDistroPython:13",
|
|
40
|
+
"eu-west-1": "arn:aws:lambda:eu-west-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
41
|
+
"eu-west-2": "arn:aws:lambda:eu-west-2:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
42
|
+
"eu-west-3": "arn:aws:lambda:eu-west-3:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
43
|
+
"il-central-1": "arn:aws:lambda:il-central-1:746669239226:layer:AWSOpenTelemetryDistroPython:13",
|
|
44
|
+
"me-central-1": "arn:aws:lambda:me-central-1:739275441131:layer:AWSOpenTelemetryDistroPython:13",
|
|
45
|
+
"me-south-1": "arn:aws:lambda:me-south-1:980921751758:layer:AWSOpenTelemetryDistroPython:13",
|
|
46
|
+
"mx-central-1": "arn:aws:lambda:mx-central-1:610118373846:layer:AWSOpenTelemetryDistroPython:4",
|
|
47
|
+
"sa-east-1": "arn:aws:lambda:sa-east-1:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
48
|
+
"us-east-1": "arn:aws:lambda:us-east-1:615299751070:layer:AWSOpenTelemetryDistroPython:19",
|
|
49
|
+
"us-east-2": "arn:aws:lambda:us-east-2:615299751070:layer:AWSOpenTelemetryDistroPython:16",
|
|
50
|
+
"us-west-1": "arn:aws:lambda:us-west-1:615299751070:layer:AWSOpenTelemetryDistroPython:23",
|
|
51
|
+
"us-west-2": "arn:aws:lambda:us-west-2:615299751070:layer:AWSOpenTelemetryDistroPython:23",
|
|
52
|
+
"us-gov-east-1": "arn:aws-us-gov:lambda:us-gov-east-1:399711857375:layer:AWSOpenTelemetryDistroPython:1",
|
|
53
|
+
"us-gov-west-1": "arn:aws-us-gov:lambda:us-gov-west-1:399727141365:layer:AWSOpenTelemetryDistroPython:1"
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Instructions
|
|
58
|
+
|
|
59
|
+
### Step 1: Add IAM Permissions
|
|
60
|
+
|
|
61
|
+
Add the AWS managed policy `CloudWatchLambdaApplicationSignalsExecutionRolePolicy` to the Lambda function's execution role.
|
|
62
|
+
|
|
63
|
+
**CDK:**
|
|
64
|
+
```typescript
|
|
65
|
+
const role = new iam.Role(this, 'LambdaRole', {
|
|
66
|
+
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
|
|
67
|
+
managedPolicies: [
|
|
68
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
|
|
69
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchLambdaApplicationSignalsExecutionRolePolicy'),
|
|
70
|
+
// ... keep existing policies
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const myFunction = new lambda.Function(this, 'MyFunction', {
|
|
75
|
+
// ... existing configuration
|
|
76
|
+
role: role,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Terraform:**
|
|
81
|
+
```hcl
|
|
82
|
+
resource "aws_iam_role" "lambda_role" {
|
|
83
|
+
name = "lambda-role"
|
|
84
|
+
assume_role_policy = jsonencode({
|
|
85
|
+
Version = "2012-10-17"
|
|
86
|
+
Statement = [
|
|
87
|
+
{
|
|
88
|
+
Action = "sts:AssumeRole"
|
|
89
|
+
Effect = "Allow"
|
|
90
|
+
Principal = {
|
|
91
|
+
Service = "lambda.amazonaws.com"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
resource "aws_iam_role_policy_attachment" "lambda_basic" {
|
|
99
|
+
role = aws_iam_role.lambda_role.name
|
|
100
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
resource "aws_iam_role_policy_attachment" "application_signals" {
|
|
104
|
+
role = aws_iam_role.lambda_role.name
|
|
105
|
+
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaApplicationSignalsExecutionRolePolicy"
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
resource "aws_lambda_function" "my_function" {
|
|
109
|
+
# ... existing configuration
|
|
110
|
+
role = aws_iam_role.lambda_role.arn
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**CloudFormation:**
|
|
115
|
+
```yaml
|
|
116
|
+
LambdaRole:
|
|
117
|
+
Type: AWS::IAM::Role
|
|
118
|
+
Properties:
|
|
119
|
+
AssumeRolePolicyDocument:
|
|
120
|
+
Version: '2012-10-17'
|
|
121
|
+
Statement:
|
|
122
|
+
- Effect: Allow
|
|
123
|
+
Principal:
|
|
124
|
+
Service: lambda.amazonaws.com
|
|
125
|
+
Action: sts:AssumeRole
|
|
126
|
+
ManagedPolicyArns:
|
|
127
|
+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
|
|
128
|
+
- arn:aws:iam::aws:policy/CloudWatchLambdaApplicationSignalsExecutionRolePolicy
|
|
129
|
+
# ... keep existing policies
|
|
130
|
+
|
|
131
|
+
MyFunction:
|
|
132
|
+
Type: AWS::Lambda::Function
|
|
133
|
+
Properties:
|
|
134
|
+
# ... existing configuration
|
|
135
|
+
Role: !GetAtt LambdaRole.Arn
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Step 2: Enable X-Ray Active Tracing
|
|
139
|
+
|
|
140
|
+
**CDK:**
|
|
141
|
+
```typescript
|
|
142
|
+
const myFunction = new lambda.Function(this, 'MyFunction', {
|
|
143
|
+
// ... existing configuration
|
|
144
|
+
tracing: lambda.Tracing.ACTIVE,
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Terraform:**
|
|
149
|
+
```hcl
|
|
150
|
+
resource "aws_lambda_function" "my_function" {
|
|
151
|
+
# ... existing configuration
|
|
152
|
+
tracing_config {
|
|
153
|
+
mode = "Active"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**CloudFormation:**
|
|
159
|
+
```yaml
|
|
160
|
+
MyFunction:
|
|
161
|
+
Type: AWS::Lambda::Function
|
|
162
|
+
Properties:
|
|
163
|
+
# ... existing configuration
|
|
164
|
+
TracingConfig:
|
|
165
|
+
Mode: Active
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Step 3: Add ADOT Python Lambda Layer
|
|
169
|
+
|
|
170
|
+
Use the layer name `AWSOpenTelemetryDistroPython` with automatic region detection. The code below includes a complete mapping that will automatically select the correct layer ARN based on your deployment region.
|
|
171
|
+
|
|
172
|
+
**CDK:**
|
|
173
|
+
```typescript
|
|
174
|
+
const layerArns: { [region: string]: string } = {
|
|
175
|
+
'af-south-1': 'arn:aws:lambda:af-south-1:904233096616:layer:AWSOpenTelemetryDistroPython:13',
|
|
176
|
+
'ap-east-1': 'arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroPython:13',
|
|
177
|
+
// ... (see Region-Specific Layer ARNs section above for complete mapping)
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const myFunction = new lambda.Function(this, 'MyFunction', {
|
|
181
|
+
// ... existing configuration
|
|
182
|
+
layers: [
|
|
183
|
+
// ... keep existing layers
|
|
184
|
+
lambda.LayerVersion.fromLayerVersionArn(
|
|
185
|
+
this,
|
|
186
|
+
'AdotLayer',
|
|
187
|
+
layerArns[this.region]
|
|
188
|
+
),
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Terraform:**
|
|
194
|
+
```hcl
|
|
195
|
+
locals {
|
|
196
|
+
layer_arns = {
|
|
197
|
+
"af-south-1" = "arn:aws:lambda:af-south-1:904233096616:layer:AWSOpenTelemetryDistroPython:13"
|
|
198
|
+
"ap-east-1" = "arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroPython:13"
|
|
199
|
+
# ... (see Region-Specific Layer ARNs section above for complete mapping)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
data "aws_region" "current" {}
|
|
204
|
+
|
|
205
|
+
resource "aws_lambda_function" "my_function" {
|
|
206
|
+
# ... existing configuration
|
|
207
|
+
layers = [
|
|
208
|
+
# ... keep existing layers
|
|
209
|
+
local.layer_arns[data.aws_region.current.name]
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**CloudFormation:**
|
|
215
|
+
```yaml
|
|
216
|
+
Mappings:
|
|
217
|
+
LayerArns:
|
|
218
|
+
af-south-1:
|
|
219
|
+
arn: arn:aws:lambda:af-south-1:904233096616:layer:AWSOpenTelemetryDistroPython:13
|
|
220
|
+
ap-east-1:
|
|
221
|
+
arn: arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroPython:13
|
|
222
|
+
# ... (see Region-Specific Layer ARNs section above for complete mapping)
|
|
223
|
+
|
|
224
|
+
Resources:
|
|
225
|
+
MyFunction:
|
|
226
|
+
Type: AWS::Lambda::Function
|
|
227
|
+
Properties:
|
|
228
|
+
# ... existing configuration
|
|
229
|
+
Layers:
|
|
230
|
+
# ... keep existing layers
|
|
231
|
+
- !FindInMap [LayerArns, !Ref 'AWS::Region', arn]
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Step 4: Set Environment Variable
|
|
235
|
+
|
|
236
|
+
Add the `AWS_LAMBDA_EXEC_WRAPPER` environment variable with value `/opt/otel-instrument`.
|
|
237
|
+
|
|
238
|
+
**CDK:**
|
|
239
|
+
```typescript
|
|
240
|
+
const myFunction = new lambda.Function(this, 'MyFunction', {
|
|
241
|
+
// ... existing configuration
|
|
242
|
+
environment: {
|
|
243
|
+
// ... keep existing environment variables
|
|
244
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/otel-instrument',
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Terraform:**
|
|
250
|
+
```hcl
|
|
251
|
+
resource "aws_lambda_function" "my_function" {
|
|
252
|
+
# ... existing configuration
|
|
253
|
+
environment {
|
|
254
|
+
variables = {
|
|
255
|
+
# ... keep existing environment variables
|
|
256
|
+
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-instrument"
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**CloudFormation:**
|
|
263
|
+
```yaml
|
|
264
|
+
MyFunction:
|
|
265
|
+
Type: AWS::Lambda::Function
|
|
266
|
+
Properties:
|
|
267
|
+
# ... existing configuration
|
|
268
|
+
Environment:
|
|
269
|
+
Variables:
|
|
270
|
+
# ... keep existing environment variables
|
|
271
|
+
AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Complete Example
|
|
275
|
+
|
|
276
|
+
**CDK:**
|
|
277
|
+
```typescript
|
|
278
|
+
const layerArns: { [region: string]: string } = {
|
|
279
|
+
'af-south-1': 'arn:aws:lambda:af-south-1:904233096616:layer:AWSOpenTelemetryDistroPython:13',
|
|
280
|
+
'ap-east-1': 'arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroPython:13',
|
|
281
|
+
// ... (see Region-Specific Layer ARNs section above for complete mapping)
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const pythonFunction = new lambda.Function(this, 'PythonFunction', {
|
|
285
|
+
runtime: lambda.Runtime.PYTHON_3_11,
|
|
286
|
+
handler: 'app.handler',
|
|
287
|
+
code: lambda.Code.fromAsset('src'),
|
|
288
|
+
tracing: lambda.Tracing.ACTIVE,
|
|
289
|
+
layers: [
|
|
290
|
+
lambda.LayerVersion.fromLayerVersionArn(
|
|
291
|
+
this,
|
|
292
|
+
'AdotLayer',
|
|
293
|
+
layerArns[this.region]
|
|
294
|
+
),
|
|
295
|
+
],
|
|
296
|
+
environment: {
|
|
297
|
+
AWS_LAMBDA_EXEC_WRAPPER: '/opt/otel-instrument',
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Completion
|
|
303
|
+
|
|
304
|
+
**Tell the user:**
|
|
305
|
+
|
|
306
|
+
"I've completed the Application Signals enablement for your Python Lambda function. Here's what I modified:
|
|
307
|
+
|
|
308
|
+
**Configuration Changes:**
|
|
309
|
+
- IAM Permissions: Added CloudWatchLambdaApplicationSignalsExecutionRolePolicy
|
|
310
|
+
- X-Ray Tracing: Enabled active tracing
|
|
311
|
+
- ADOT Layer: Added AWSOpenTelemetryDistroPython layer
|
|
312
|
+
- Environment Variable: Set AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
|
|
313
|
+
|
|
314
|
+
**Next Steps:**
|
|
315
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
316
|
+
2. Review the changes I made using `git diff`
|
|
317
|
+
3. Deploy your infrastructure:
|
|
318
|
+
- For CDK: `cdk deploy`
|
|
319
|
+
- For Terraform: `terraform apply`
|
|
320
|
+
- For CloudFormation: Deploy your stack
|
|
321
|
+
4. After deployment, invoke your Lambda function to generate telemetry data
|
|
322
|
+
|
|
323
|
+
**Verification:**
|
|
324
|
+
Once deployed, you can verify Application Signals is working by:
|
|
325
|
+
- Opening the AWS CloudWatch Console
|
|
326
|
+
- Navigating to Application Signals → Services
|
|
327
|
+
- Looking for your Lambda function service
|
|
328
|
+
- Checking that traces and metrics are being collected
|
|
329
|
+
|
|
330
|
+
**Monitor Application Health:**
|
|
331
|
+
After enablement, you can monitor your Lambda function's operational health using Application Signals dashboards. For more information, see [Monitor the operational health of your applications with Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Services.html).
|
|
332
|
+
|
|
333
|
+
**Troubleshooting**
|
|
334
|
+
If you encounter any other issues, refer to the [CloudWatch APM troubleshooting guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html).
|
|
335
|
+
|
|
336
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""CloudWatch Application Signals MCP Server - Enablement Tools."""
|
|
16
|
+
|
|
17
|
+
from loguru import logger
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def get_enablement_guide(
|
|
22
|
+
service_platform: str,
|
|
23
|
+
service_language: str,
|
|
24
|
+
iac_directory: str,
|
|
25
|
+
app_directory: str,
|
|
26
|
+
) -> str:
|
|
27
|
+
"""Get enablement guide for AWS Application Signals.
|
|
28
|
+
|
|
29
|
+
Use this tool when the user wants to:
|
|
30
|
+
- Enable observability, monitoring, or Application Signals for their AWS service
|
|
31
|
+
- Set up automatic instrumentation for their application on AWS
|
|
32
|
+
- Instrument their service running on EC2, ECS, Lambda, or EKS
|
|
33
|
+
|
|
34
|
+
This tool returns step-by-step enablement instructions that guide you through
|
|
35
|
+
modifying your infrastructure and application code to enable Application Signals,
|
|
36
|
+
which is the preferred way to enable automatic instrumentation for services on AWS.
|
|
37
|
+
|
|
38
|
+
Before calling this tool:
|
|
39
|
+
1. Ensure you know where the application code is located and that you have read/write permissions
|
|
40
|
+
2. Ensure you know where the IaC code is located and that you have read/write permissions
|
|
41
|
+
3. If the user provides relative paths or descriptions (e.g., "./infrastructure", "in the root"):
|
|
42
|
+
- Use the Bash tool to run 'pwd' to get the current working directory
|
|
43
|
+
- Use file exploration tools to locate the directories
|
|
44
|
+
- Convert relative paths to absolute paths before calling this tool
|
|
45
|
+
4. This tool REQUIRES absolute paths for both iac_directory and app_directory parameters
|
|
46
|
+
|
|
47
|
+
After calling this tool, you should:
|
|
48
|
+
1. Review the enablement guide and create a visible, trackable checklist of required changes
|
|
49
|
+
- Use your system's task tracking mechanism (todo lists, markdown checklists, etc.)
|
|
50
|
+
- Each item should be granular enough to complete in one step
|
|
51
|
+
- Mark items as complete as you finish them to track progress
|
|
52
|
+
- This allows you to resume work if the context window fills up
|
|
53
|
+
2. Work through the checklist systematically, one item at a time:
|
|
54
|
+
- Identify the specific file(s) that need modification for this step
|
|
55
|
+
- Read only the relevant file(s) (DO NOT load all IaC and app files at once)
|
|
56
|
+
- Apply the changes as specified in the guide
|
|
57
|
+
3. Keep context focused: Only load files needed for the current checklist item
|
|
58
|
+
|
|
59
|
+
Important guidelines:
|
|
60
|
+
- Use ABSOLUTE PATHS when reading and writing files
|
|
61
|
+
- Do NOT modify actual application logic files (.py, .js, .java source code), only
|
|
62
|
+
modify IaC code, Dockerfiles, and dependency files (requirements.txt, pyproject.toml,
|
|
63
|
+
package.json, pom.xml, build.gradle, *.csproj, etc.) as instructed by the guide.
|
|
64
|
+
- Read application files if needed to understand the setup, but avoid modifying them
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
service_platform: The AWS platform where the service runs.
|
|
68
|
+
MUST be one of: 'ec2', 'ecs', 'lambda', 'eks' (lowercase, exact match).
|
|
69
|
+
To help user determine: check their IaC for ECS services, Lambda functions, EKS deployments, or EC2 instances.
|
|
70
|
+
service_language: The service's programming language.
|
|
71
|
+
MUST be one of: 'python', 'nodejs', 'java', 'dotnet' (lowercase, exact match).
|
|
72
|
+
IMPORTANT: Use 'nodejs' (not 'js', 'node', or 'javascript'), 'dotnet' (not 'csharp' or 'c#').
|
|
73
|
+
To help user determine: check for package.json (nodejs), requirements.txt (python), pom.xml (java), or .csproj (dotnet).
|
|
74
|
+
iac_directory: ABSOLUTE path to the Infrastructure as Code (IaC) directory (e.g., /home/user/project/infrastructure)
|
|
75
|
+
app_directory: ABSOLUTE path to the application code directory (e.g., /home/user/project/app)
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Markdown-formatted enablement guide with step-by-step instructions
|
|
79
|
+
"""
|
|
80
|
+
logger.debug(
|
|
81
|
+
f'get_enablement_guide called: service_platform={service_platform}, service_language={service_language}, '
|
|
82
|
+
f'iac_directory={iac_directory}, app_directory={app_directory}'
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Normalize to lowercase
|
|
86
|
+
platform_str = service_platform.lower().strip()
|
|
87
|
+
language_str = service_language.lower().strip()
|
|
88
|
+
|
|
89
|
+
guides_dir = Path(__file__).parent / 'enablement_guides'
|
|
90
|
+
template_file = (
|
|
91
|
+
guides_dir / 'templates' / platform_str / f'{platform_str}-{language_str}-enablement.md'
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
logger.debug(f'Looking for enablement guide: {template_file}')
|
|
95
|
+
|
|
96
|
+
# Validate that paths are absolute
|
|
97
|
+
iac_path = Path(iac_directory)
|
|
98
|
+
app_path = Path(app_directory)
|
|
99
|
+
|
|
100
|
+
if not iac_path.is_absolute() or not app_path.is_absolute():
|
|
101
|
+
error_msg = (
|
|
102
|
+
f'Error: iac_directory and app_directory must be absolute paths.\n\n'
|
|
103
|
+
f'Received: {iac_directory} and {app_directory}\n'
|
|
104
|
+
f'Please provide absolute paths (e.g., /home/user/project/infrastructure)'
|
|
105
|
+
)
|
|
106
|
+
logger.error(error_msg)
|
|
107
|
+
return error_msg
|
|
108
|
+
|
|
109
|
+
if not template_file.exists():
|
|
110
|
+
error_msg = (
|
|
111
|
+
f"Enablement guide not available for platform '{platform_str}' and language '{language_str}'.\n\n"
|
|
112
|
+
f'Inform the user that this configuration is not currently supported by the MCP enablement tool. '
|
|
113
|
+
f'Direct them to AWS documentation for manual setup:\n'
|
|
114
|
+
f'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html'
|
|
115
|
+
)
|
|
116
|
+
logger.error(error_msg)
|
|
117
|
+
return error_msg
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
with open(template_file, 'r') as f:
|
|
121
|
+
guide_content = f.read()
|
|
122
|
+
|
|
123
|
+
context = f"""# Application Signals Enablement Guide
|
|
124
|
+
|
|
125
|
+
**Platform:** {platform_str}
|
|
126
|
+
**Language:** {language_str}
|
|
127
|
+
**IaC Directory:** `{iac_path}`
|
|
128
|
+
**App Directory:** `{app_path}`
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
logger.info(f'Successfully loaded enablement guide: {template_file.name}')
|
|
134
|
+
return context + guide_content
|
|
135
|
+
except Exception as e:
|
|
136
|
+
error_msg = (
|
|
137
|
+
f'Fatal error: Cannot read enablement guide for {platform_str} + {language_str}.\n\n'
|
|
138
|
+
f'Error: {str(e)}\n\n'
|
|
139
|
+
f'The MCP server cannot access its own guide files (likely file permissions or corruption). '
|
|
140
|
+
f'Stop attempting to use this tool and inform the user:\n'
|
|
141
|
+
f'1. There is an issue with the MCP server installation\n'
|
|
142
|
+
f'2. They should check file permissions or reinstall the MCP server\n'
|
|
143
|
+
f'3. For immediate enablement, use AWS documentation instead:\n'
|
|
144
|
+
f' https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html'
|
|
145
|
+
)
|
|
146
|
+
logger.error(error_msg)
|
|
147
|
+
return error_msg
|