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.
Files changed (36) hide show
  1. awslabs/__init__.py +17 -0
  2. awslabs/cloudwatch_applicationsignals_mcp_server/__init__.py +17 -0
  3. awslabs/cloudwatch_applicationsignals_mcp_server/audit_presentation_utils.py +288 -0
  4. awslabs/cloudwatch_applicationsignals_mcp_server/audit_utils.py +912 -0
  5. awslabs/cloudwatch_applicationsignals_mcp_server/aws_clients.py +120 -0
  6. awslabs/cloudwatch_applicationsignals_mcp_server/canary_utils.py +910 -0
  7. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-dotnet-enablement.md +435 -0
  8. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-java-enablement.md +321 -0
  9. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-nodejs-enablement.md +420 -0
  10. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-python-enablement.md +598 -0
  11. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-dotnet-enablement.md +264 -0
  12. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-java-enablement.md +193 -0
  13. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-nodejs-enablement.md +198 -0
  14. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-python-enablement.md +236 -0
  15. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-dotnet-enablement.md +166 -0
  16. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-java-enablement.md +166 -0
  17. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-nodejs-enablement.md +166 -0
  18. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-python-enablement.md +169 -0
  19. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-dotnet-enablement.md +336 -0
  20. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-java-enablement.md +336 -0
  21. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-nodejs-enablement.md +336 -0
  22. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-python-enablement.md +336 -0
  23. awslabs/cloudwatch_applicationsignals_mcp_server/enablement_tools.py +147 -0
  24. awslabs/cloudwatch_applicationsignals_mcp_server/server.py +1505 -0
  25. awslabs/cloudwatch_applicationsignals_mcp_server/service_audit_utils.py +231 -0
  26. awslabs/cloudwatch_applicationsignals_mcp_server/service_tools.py +659 -0
  27. awslabs/cloudwatch_applicationsignals_mcp_server/sli_report_client.py +333 -0
  28. awslabs/cloudwatch_applicationsignals_mcp_server/slo_tools.py +386 -0
  29. awslabs/cloudwatch_applicationsignals_mcp_server/trace_tools.py +784 -0
  30. awslabs/cloudwatch_applicationsignals_mcp_server/utils.py +172 -0
  31. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/METADATA +808 -0
  32. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/RECORD +36 -0
  33. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/WHEEL +4 -0
  34. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/entry_points.txt +2 -0
  35. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/LICENSE +174 -0
  36. awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/NOTICE +2 -0
@@ -0,0 +1,321 @@
1
+ # Task: Enable AWS Application Signals for Java on EC2
2
+
3
+ Your task is to modify Infrastructure as Code (IaC) files to enable AWS Application Signals for a Java application running on EC2 instances. You will update IAM permissions, install monitoring agents, and configure OpenTelemetry instrumentation through UserData scripts.
4
+
5
+ ## What You Will Accomplish
6
+
7
+ After completing this task:
8
+ - The EC2 instance will have permissions to send telemetry data to CloudWatch
9
+ - The CloudWatch Agent will be installed and configured for Application Signals
10
+ - The Java application will be automatically instrumented with AWS Distro for OpenTelemetry (ADOT)
11
+ - Traces, metrics, and performance data will appear in the CloudWatch Application Signals console
12
+ - The user will be able to see service maps, SLOs, and application performance metrics without manual code instrumentation
13
+
14
+ ## Critical Requirements
15
+
16
+ **Error Handling:**
17
+ - If you cannot determine required values from the IaC, STOP and ask the user
18
+ - For multiple EC2 instances, ask which one(s) to modify
19
+ - Preserve all existing UserData commands; add new ones in sequence
20
+
21
+ **Do NOT:**
22
+ - Run deployment commands automatically (`cdk deploy`, `terraform apply`, etc.)
23
+ - Remove existing application startup logic
24
+ - Skip the user approval step before deployment
25
+
26
+ ## IaC Tool Support
27
+
28
+ **Code examples use CDK TypeScript syntax.** If you are working with Terraform or CloudFormation, translate the CDK syntax to the appropriate format while keeping all bash commands identical. The UserData bash commands (CloudWatch Agent installation, ADOT installation, environment variables) are universal across all IaC tools - only the wrapper syntax differs.
29
+
30
+ ## Before You Start: Gather Required Information
31
+
32
+ Execute these steps to collect the information needed for configuration:
33
+
34
+ ### Step 1: Determine Deployment Type
35
+
36
+ Read the UserData script and look for the application startup command. This is typically one of the last commands in UserData.
37
+
38
+ **If you see:**
39
+ - `docker run` or `docker start` → Docker deployment
40
+ - `java -jar`, `mvn spring-boot:run`, `gradle bootRun`, or similar → Non-Docker deployment
41
+
42
+ **If unclear:**
43
+ - Ask the user: "Is your Java application running in a Docker container or directly on the EC2 instance?" DO NOT GUESS
44
+
45
+ **Critical distinction:** Where does the Java process run?
46
+ - **Docker:** Java runs inside a container → Modify Dockerfile
47
+ - **Non-Docker:** Java runs directly on EC2 → Modify UserData
48
+
49
+ ### Step 2: Extract Placeholder Values
50
+
51
+ Analyze the existing IaC to determine these values for Application Signals enablement:
52
+
53
+ - `{{SERVICE_NAME}}`
54
+ - **Why It Matters:** Sets the service name displayed in Application Signals console via `OTEL_RESOURCE_ATTRIBUTES=service.name={{SERVICE_NAME}}`
55
+ - **How to Find It:** Use the application name, stack name, or construct ID. Look for service/app names in the IaC.
56
+ - **Example Value:** `my-java-app`
57
+ - **Required For:** Both Docker and non-Docker
58
+
59
+ For Docker-based deployments you will also need to find these additional values:
60
+
61
+ - `{{PORT}}`
62
+ - **Why It Matters:** Docker port mapping that ensures the container is accessible on the correct port
63
+ - **How to Find It:** Find port mappings in `docker run -p` commands or security group ingress rules
64
+ - **Example Value:** `8080`
65
+ - **Required For:** Docker
66
+ - `{{APP_NAME}}`
67
+ - **Why It Matters:** Used to reference the container for operations like `docker logs {{APP_NAME}}`, `docker exec`, health checks, etc.
68
+ - **How to Find It:** Find container name in `docker run --name` or use `{{SERVICE_NAME}}-container`
69
+ - **Example Value:** `java-springboot-app`
70
+ - **Required For:** Docker
71
+ - `{{IMAGE_URI}}`
72
+ - **Why It Matters:** This is the identifier for the application that Docker will run
73
+ - **How to Find It:** Find the Docker image in `docker run` or `docker pull` commands
74
+ - **Example Value:** `123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest`
75
+ - **Required For:** Docker
76
+
77
+ **If you cannot determine a value:** Ask the user for clarification before proceeding. Do not guess or make up values.
78
+
79
+ ### Step 3: Identify Instance OS
80
+
81
+ Determine the operating system to use the correct package manager and installation commands.
82
+
83
+ **Amazon Linux**
84
+ - **Amazon Linux 2:** Use `yum` package manager
85
+ - **Amazon Linux 2023:** Use `dnf` package manager
86
+ - **How to detect:** Look for existing package install commands in UserData (check for `yum` or `dnf`), or look for AMI references containing `al2` or `al2023`
87
+
88
+ **Other Linux distributions:**
89
+ - **Ubuntu/Debian:** Use `apt` package manager
90
+ - **Fedora/RHEL/CentOS:** Use `dnf` or `yum` package manager
91
+
92
+ **If unclear:** Look for AMI name/ID in the IaC or ask the user which OS the EC2 instance is running. Do not guess or make up values.
93
+
94
+ ## Instructions
95
+
96
+ Follow these steps in sequence:
97
+
98
+ ### Step 1: Locate the IaC Files
99
+
100
+ **Search for EC2 instance definitions** using these patterns:
101
+
102
+ **CDK:**
103
+ ```
104
+ new ec2.Instance(
105
+ ec2.Instance(
106
+ CfnInstance(
107
+ ```
108
+
109
+ **Terraform:**
110
+ ```
111
+ resource "aws_instance"
112
+ ```
113
+
114
+ **CloudFormation:**
115
+ ```
116
+ AWS::EC2::Instance
117
+ ```
118
+
119
+ **Read the file(s)** containing the EC2 instance definition. You need to identify:
120
+ 1. The instance resource/construct
121
+ 2. The IAM role attached to the instance
122
+ 3. The UserData script or property
123
+
124
+ ### Step 2: Locate the IAM Role
125
+
126
+ Find the IAM role attached to the EC2 instance
127
+
128
+ **CDK:**
129
+ ```typescript
130
+ role: someRole
131
+ new iam.Role(this, 'RoleName'
132
+ ```
133
+
134
+ ### Step 3: Update the IAM Role
135
+
136
+ Add the CloudWatch Agent Server Policy to the IAM role's managed policies.
137
+
138
+ **CDK:**
139
+ ```typescript
140
+ const role = new iam.Role(this, 'AppRole', {
141
+ assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
142
+ managedPolicies: [
143
+ iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy'),
144
+ // ... keep existing policies
145
+ ],
146
+ });
147
+ ```
148
+
149
+ ### Step 4: Modify UserData - Add Prerequisites
150
+
151
+ Add a CloudWatch Agent installation command to the UserData script.
152
+
153
+ **CRITICAL for Terraform Users:** When modifying Terraform `user_data` heredocs, you MUST preserve the EXACT indentation of existing lines. Terraform's `<<-EOF` syntax strips leading whitespace, but only if indentation is consistent. When adding new bash commands:
154
+ - Count the leading spaces/tabs on existing lines in the heredoc
155
+ - Apply the SAME amount of leading whitespace to all new lines you add
156
+ - Do NOT modify the indentation of any existing lines
157
+
158
+ If indentation is inconsistent, Terraform will NOT strip the whitespace, causing the deployed script to have leading spaces before `#!/bin/bash`, which will cause cloud-init to fail.
159
+
160
+ **CDK TypeScript example:**
161
+ ```typescript
162
+ instance.userData.addCommands(
163
+ 'dnf install -y amazon-cloudwatch-agent', // Use dnf for AL2023, yum for AL2
164
+ // ... rest of UserData follows
165
+ );
166
+ ```
167
+
168
+ **Placement:** Add this command early in the UserData script:
169
+ - If system update commands exist (like `dnf update -y`, `apt-get update`), add it immediately after those
170
+ - If no system update commands exist, add it at the very beginning of UserData
171
+ - This should come before any application dependency installations or application setup commands
172
+
173
+ **For other Linux distributions:** CloudWatch Agent may not be available via the OS package manager. Refer to [AWS CloudWatch Agent installation docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/manual-installation.html) for distribution-specific instructions.
174
+
175
+ ### Step 5: Modify UserData - Configure CloudWatch Agent
176
+
177
+ The CloudWatch Agent was installed in Step 4. Now configure it for Application Signals:
178
+
179
+ **CDK TypeScript example:**
180
+ ```typescript
181
+ instance.userData.addCommands(
182
+ '# Create CloudWatch Agent configuration for Application Signals',
183
+ "cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json << 'EOF'",
184
+ '{',
185
+ ' "traces": {',
186
+ ' "traces_collected": {',
187
+ ' "application_signals": {}',
188
+ ' }',
189
+ ' },',
190
+ ' "logs": {',
191
+ ' "metrics_collected": {',
192
+ ' "application_signals": {}',
193
+ ' }',
194
+ ' }',
195
+ '}',
196
+ 'EOF',
197
+ '',
198
+ '# Start CloudWatch Agent with Application Signals configuration',
199
+ '/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \\',
200
+ ' -a fetch-config \\',
201
+ ' -m ec2 \\',
202
+ ' -s \\',
203
+ ' -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json',
204
+ );
205
+ ```
206
+
207
+ ### Step 6: Install ADOT Java Auto-Instrumentation SDK
208
+
209
+ Choose based on deployment type identified in "Before You Start".
210
+
211
+ #### Option A: Docker Deployment - Modify Dockerfile
212
+
213
+ For Docker deployments, modify the `Dockerfile` in the application directory.
214
+
215
+ Add these lines to download the ADOT Java agent JAR file. Place this AFTER any `RUN` commands that install dependencies, but BEFORE the `CMD` line:
216
+
217
+ ```dockerfile
218
+ RUN curl -Lo /opt/aws-opentelemetry-agent.jar \
219
+ https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar
220
+ ```
221
+
222
+ **Why modify Dockerfile, not UserData:** The ADOT agent JAR must be available inside the container image, not on the EC2 host. UserData commands run on the host and won't affect the containerized application.
223
+
224
+ #### Option B: Non-Docker Deployment - Modify UserData
225
+
226
+ For non-Docker deployments, add to UserData AFTER CloudWatch Agent configuration:
227
+
228
+ ```typescript
229
+ instance.userData.addCommands(
230
+ '# Download ADOT Java agent',
231
+ 'curl -Lo /opt/aws-opentelemetry-agent.jar \\',
232
+ ' https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar',
233
+ );
234
+ ```
235
+
236
+ ### Step 7: Modify UserData - Configure Application
237
+
238
+ Choose based on deployment type identified in "Before You Start".
239
+
240
+ #### Option A: Docker Deployment
241
+
242
+ **Critical Docker configuration:** The `--network host` flag is REQUIRED for all Docker deployments. Without it, the container cannot reach the CloudWatch Agent at `localhost:4316` because `localhost` inside a container refers to the container's network namespace, not the EC2 host.
243
+
244
+ Find the existing `docker run` command in UserData. Replace it with:
245
+
246
+ ```typescript
247
+ instance.userData.addCommands(
248
+ '# Run container with Application Signals environment variables',
249
+ `docker run -d --name {{APP_NAME}} \\`,
250
+ ` -p {{PORT}}:{{PORT}} \\`,
251
+ ` -e JAVA_TOOL_OPTIONS=-javaagent:/opt/aws-opentelemetry-agent.jar \\`,
252
+ ` -e OTEL_METRICS_EXPORTER=none \\`,
253
+ ` -e OTEL_LOGS_EXPORTER=none \\`,
254
+ ` -e OTEL_AWS_APPLICATION_SIGNALS_ENABLED=true \\`,
255
+ ` -e OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \\`,
256
+ ` -e OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT=http://localhost:4316/v1/metrics \\`,
257
+ ` -e OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4316/v1/traces \\`,
258
+ ` -e OTEL_RESOURCE_ATTRIBUTES=service.name={{SERVICE_NAME}} \\`,
259
+ ` --network host \\`,
260
+ ` {{IMAGE_URI}}`,
261
+ );
262
+ ```
263
+
264
+ #### Option B: Non-Docker Deployment
265
+
266
+ Find the existing command that starts the Java application. Add the environment variables BEFORE it:
267
+
268
+ ```typescript
269
+ instance.userData.addCommands(
270
+ '# Set OpenTelemetry environment variables',
271
+ 'export JAVA_TOOL_OPTIONS=-javaagent:/opt/aws-opentelemetry-agent.jar',
272
+ 'export OTEL_METRICS_EXPORTER=none',
273
+ 'export OTEL_LOGS_EXPORTER=none',
274
+ 'export OTEL_AWS_APPLICATION_SIGNALS_ENABLED=true',
275
+ 'export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf',
276
+ 'export OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT=http://localhost:4316/v1/metrics',
277
+ 'export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4316/v1/traces',
278
+ 'export OTEL_RESOURCE_ATTRIBUTES=service.name={{SERVICE_NAME}}',
279
+ '',
280
+ '# Start application (existing command remains unchanged)',
281
+ '# Example: java -jar app.jar',
282
+ '# The JAVA_TOOL_OPTIONS will automatically attach the agent',
283
+ );
284
+ ```
285
+
286
+ ## Completion
287
+
288
+ **Tell the user:**
289
+
290
+ "I've completed the Application Signals enablement for your Java application. Here's what I modified:
291
+
292
+ **Files Changed:**
293
+ - IAM role: Added CloudWatchAgentServerPolicy
294
+ - UserData: Installed and configured CloudWatch Agent
295
+ - UserData: Downloaded ADOT Java agent JAR
296
+ - UserData/Service file: Added OpenTelemetry environment variables (`JAVA_TOOL_OPTIONS`)
297
+ - Dockerfile: Downloaded ADOT Java agent JAR (if using Docker)
298
+
299
+ **Next Steps:**
300
+ 1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
301
+ 2. Review the changes I made using `git diff`
302
+ 3. Deploy your infrastructure:
303
+ - For CDK: `cdk deploy`
304
+ - For Terraform: `terraform apply`
305
+ - For CloudFormation: Deploy your stack
306
+ 4. After deployment, wait 5-10 minutes for telemetry data to start flowing
307
+
308
+ **Verification:**
309
+ Once deployed, you can verify Application Signals is working by:
310
+ - Opening the AWS CloudWatch Console
311
+ - Navigating to Application Signals → Services
312
+ - Looking for your service (named: {{SERVICE_NAME}})
313
+ - Checking that traces and metrics are being collected
314
+
315
+ **Monitor Application Health:**
316
+ After enablement, you can monitor your application'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).
317
+
318
+ **Troubleshooting**
319
+ 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).
320
+
321
+ Let me know if you'd like me to make any adjustments before you deploy!"