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,166 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for Node.js Applications on Amazon EKS
|
|
2
|
+
|
|
3
|
+
This guide shows how to modify the existing CDK and Terraform infrastructure code to enable AWS Application Signals for Node.js applications running on Amazon EKS.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Application Signals enabled in your AWS account (see [Enable Application Signals in your account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html))
|
|
8
|
+
- Existing EKS cluster deployed using the provided CDK or Terraform code
|
|
9
|
+
- Node.js application containerized and pushed to ECR
|
|
10
|
+
- AWS CLI configured with appropriate permissions
|
|
11
|
+
|
|
12
|
+
## Critical Requirements
|
|
13
|
+
|
|
14
|
+
**Error Handling:**
|
|
15
|
+
- If you cannot determine required values from the IaC, STOP and ask the user
|
|
16
|
+
- For multiple EC2 instances, ask which one(s) to modify
|
|
17
|
+
- Preserve all existing UserData commands; add new ones in sequence
|
|
18
|
+
|
|
19
|
+
**Do NOT:**
|
|
20
|
+
- Run deployment commands automatically (`cdk deploy`, `terraform apply`, etc.)
|
|
21
|
+
- Remove existing application startup logic
|
|
22
|
+
- Skip the user approval step before deployment
|
|
23
|
+
|
|
24
|
+
## CDK Implementation
|
|
25
|
+
|
|
26
|
+
### 1. Install CloudWatch Observability Add-on
|
|
27
|
+
|
|
28
|
+
Create an IAM role and install the CloudWatch Observability add-on:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import * as eks from 'aws-cdk-lib/aws-eks';
|
|
32
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
33
|
+
|
|
34
|
+
// Create IAM role for CloudWatch agent
|
|
35
|
+
const cloudwatchRole = new iam.Role(this, 'CloudWatchAgentAddOnRole', {
|
|
36
|
+
assumedBy: new iam.OpenIdConnectPrincipal(cluster.openIdConnectProvider),
|
|
37
|
+
managedPolicies: [
|
|
38
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Install the CloudWatch Observability add-on
|
|
43
|
+
new eks.CfnAddon(this, 'CloudWatchAddon', {
|
|
44
|
+
addonName: 'amazon-cloudwatch-observability',
|
|
45
|
+
clusterName: cluster.clusterName,
|
|
46
|
+
serviceAccountRoleArn: cloudwatchRole.roleArn
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Add Node.js Instrumentation Annotation
|
|
51
|
+
|
|
52
|
+
Update your deployment template metadata to include the Node.js instrumentation annotation:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
template: {
|
|
56
|
+
metadata: {
|
|
57
|
+
labels: { app: config.appName },
|
|
58
|
+
annotations: {
|
|
59
|
+
'instrumentation.opentelemetry.io/inject-nodejs': 'true'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// ... rest of your template configuration
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Terraform Implementation
|
|
67
|
+
|
|
68
|
+
### 1. Add CloudWatch Agent IAM Permissions
|
|
69
|
+
|
|
70
|
+
Add the CloudWatch policy to the node role:
|
|
71
|
+
|
|
72
|
+
```hcl
|
|
73
|
+
# Additional IAM policies for Application Signals
|
|
74
|
+
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_policy" {
|
|
75
|
+
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
|
|
76
|
+
role = aws_iam_role.node_role.name
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Important:** Add this policy attachment to your node group's `depends_on` block:
|
|
81
|
+
|
|
82
|
+
```hcl
|
|
83
|
+
resource "aws_eks_node_group" "app_nodes" {
|
|
84
|
+
# ... existing configuration ...
|
|
85
|
+
|
|
86
|
+
depends_on = [
|
|
87
|
+
aws_iam_role_policy_attachment.node_policy,
|
|
88
|
+
aws_iam_role_policy_attachment.cloudwatch_agent_policy
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. Install CloudWatch Observability Add-on
|
|
94
|
+
|
|
95
|
+
Add the CloudWatch Observability EKS add-on:
|
|
96
|
+
|
|
97
|
+
```hcl
|
|
98
|
+
# CloudWatch Observability Add-on
|
|
99
|
+
resource "aws_eks_addon" "cloudwatch_observability" {
|
|
100
|
+
cluster_name = aws_eks_cluster.app_cluster.name
|
|
101
|
+
addon_name = "amazon-cloudwatch-observability"
|
|
102
|
+
|
|
103
|
+
depends_on = [
|
|
104
|
+
aws_eks_node_group.app_nodes
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Add Node.js Instrumentation Annotation
|
|
110
|
+
|
|
111
|
+
Update your Kubernetes deployment template to include the Node.js instrumentation annotation:
|
|
112
|
+
|
|
113
|
+
```hcl
|
|
114
|
+
template {
|
|
115
|
+
metadata {
|
|
116
|
+
labels = {
|
|
117
|
+
app = var.app_name
|
|
118
|
+
}
|
|
119
|
+
annotations = {
|
|
120
|
+
"instrumentation.opentelemetry.io/inject-nodejs" = "true"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
# ... rest of your template configuration
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- The Node.js instrumentation annotation will cause pods to restart automatically
|
|
130
|
+
- For Node.js applications with ESM module format, see [special configuration requirements](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-EKS.html#EKS-NodeJs-ESM) in the AWS documentation
|
|
131
|
+
- It may take a few minutes for data to appear in the Application Signals console after deployment
|
|
132
|
+
|
|
133
|
+
## Completion
|
|
134
|
+
|
|
135
|
+
**Tell the user:**
|
|
136
|
+
|
|
137
|
+
"I've completed the Application Signals enablement for your Node.js application. Here's what I modified:
|
|
138
|
+
|
|
139
|
+
**Files Changed:**
|
|
140
|
+
- IAM role: Added CloudWatchAgentServerPolicy
|
|
141
|
+
- CloudWatch Observability EKS add-on: Added to the EKS Cluster
|
|
142
|
+
- Kubernetes Deployment: Instrumentation annotation added with inject-nodejs set to true
|
|
143
|
+
|
|
144
|
+
**Next Steps:**
|
|
145
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
146
|
+
2. Review the changes I made using `git diff`
|
|
147
|
+
3. Deploy your infrastructure:
|
|
148
|
+
- For CDK: `cdk deploy`
|
|
149
|
+
- For Terraform: `terraform apply`
|
|
150
|
+
- For CloudFormation: Deploy your stack
|
|
151
|
+
4. After deployment, wait 5-10 minutes for telemetry data to start flowing
|
|
152
|
+
|
|
153
|
+
**Verification:**
|
|
154
|
+
Once deployed, you can verify Application Signals is working by:
|
|
155
|
+
- Opening the AWS CloudWatch Console
|
|
156
|
+
- Navigating to Application Signals → Services
|
|
157
|
+
- Looking for your service (named: {{SERVICE_NAME}})
|
|
158
|
+
- Checking that traces and metrics are being collected
|
|
159
|
+
|
|
160
|
+
**Monitor Application Health:**
|
|
161
|
+
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).
|
|
162
|
+
|
|
163
|
+
**Troubleshooting**
|
|
164
|
+
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).
|
|
165
|
+
|
|
166
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for Python Applications on Amazon EKS
|
|
2
|
+
|
|
3
|
+
This guide shows how to modify the existing CDK and Terraform infrastructure code to enable AWS Application Signals for Python applications running on Amazon EKS.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Application Signals enabled in your AWS account (see [Enable Application Signals in your account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html))
|
|
8
|
+
- Existing EKS cluster deployed using the provided CDK or Terraform code
|
|
9
|
+
- Python application containerized and pushed to ECR
|
|
10
|
+
- AWS CLI configured with appropriate permissions
|
|
11
|
+
|
|
12
|
+
## Critical Requirements
|
|
13
|
+
|
|
14
|
+
**Error Handling:**
|
|
15
|
+
- If you cannot determine required values from the IaC, STOP and ask the user
|
|
16
|
+
- For multiple EC2 instances, ask which one(s) to modify
|
|
17
|
+
- Preserve all existing UserData commands; add new ones in sequence
|
|
18
|
+
|
|
19
|
+
**Do NOT:**
|
|
20
|
+
- Run deployment commands automatically (`cdk deploy`, `terraform apply`, etc.)
|
|
21
|
+
- Remove existing application startup logic
|
|
22
|
+
- Skip the user approval step before deployment
|
|
23
|
+
|
|
24
|
+
## CDK Implementation
|
|
25
|
+
|
|
26
|
+
### 1. Install CloudWatch Observability Add-on
|
|
27
|
+
|
|
28
|
+
Create an IAM role and install the CloudWatch Observability add-on:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import * as eks from 'aws-cdk-lib/aws-eks';
|
|
32
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
33
|
+
|
|
34
|
+
// Create IAM role for CloudWatch agent
|
|
35
|
+
const cloudwatchRole = new iam.Role(this, 'CloudWatchAgentAddOnRole', {
|
|
36
|
+
assumedBy: new iam.OpenIdConnectPrincipal(cluster.openIdConnectProvider),
|
|
37
|
+
managedPolicies: [
|
|
38
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Install the CloudWatch Observability add-on
|
|
43
|
+
new eks.CfnAddon(this, 'CloudWatchAddon', {
|
|
44
|
+
addonName: 'amazon-cloudwatch-observability',
|
|
45
|
+
clusterName: cluster.clusterName,
|
|
46
|
+
serviceAccountRoleArn: cloudwatchRole.roleArn
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Add Python Instrumentation Annotation
|
|
51
|
+
|
|
52
|
+
Update your deployment template metadata to include the Python instrumentation annotation:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
template: {
|
|
56
|
+
metadata: {
|
|
57
|
+
labels: { app: config.appName },
|
|
58
|
+
annotations: {
|
|
59
|
+
'instrumentation.opentelemetry.io/inject-python': 'true'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// ... rest of your template configuration
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Terraform Implementation
|
|
67
|
+
|
|
68
|
+
### 1. Add CloudWatch Agent IAM Permissions
|
|
69
|
+
|
|
70
|
+
Add the CloudWatch policy to the node role:
|
|
71
|
+
|
|
72
|
+
```hcl
|
|
73
|
+
# Additional IAM policies for Application Signals
|
|
74
|
+
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_policy" {
|
|
75
|
+
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
|
|
76
|
+
role = aws_iam_role.node_role.name
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Important:** Add this policy attachment to your node group's `depends_on` block:
|
|
81
|
+
|
|
82
|
+
```hcl
|
|
83
|
+
resource "aws_eks_node_group" "app_nodes" {
|
|
84
|
+
# ... existing configuration ...
|
|
85
|
+
|
|
86
|
+
depends_on = [
|
|
87
|
+
aws_iam_role_policy_attachment.node_policy,
|
|
88
|
+
aws_iam_role_policy_attachment.cloudwatch_agent_policy
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. Install CloudWatch Observability Add-on
|
|
94
|
+
|
|
95
|
+
Add the CloudWatch Observability EKS add-on:
|
|
96
|
+
|
|
97
|
+
```hcl
|
|
98
|
+
# CloudWatch Observability Add-on
|
|
99
|
+
resource "aws_eks_addon" "cloudwatch_observability" {
|
|
100
|
+
cluster_name = aws_eks_cluster.app_cluster.name
|
|
101
|
+
addon_name = "amazon-cloudwatch-observability"
|
|
102
|
+
|
|
103
|
+
depends_on = [
|
|
104
|
+
aws_eks_node_group.app_nodes
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Add Python Instrumentation Annotation
|
|
110
|
+
|
|
111
|
+
Update your Kubernetes deployment template to include the Python instrumentation annotation:
|
|
112
|
+
|
|
113
|
+
```hcl
|
|
114
|
+
template {
|
|
115
|
+
metadata {
|
|
116
|
+
labels = {
|
|
117
|
+
app = var.app_name
|
|
118
|
+
}
|
|
119
|
+
annotations = {
|
|
120
|
+
"instrumentation.opentelemetry.io/inject-python" = "true"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
# ... rest of your template configuration
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- The Python instrumentation annotation will cause pods to restart automatically
|
|
130
|
+
- Ensure your Python application meets the [prerequisites](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html#Application-Signals-troubleshoot-starting-Python) for Application Signals
|
|
131
|
+
- It may take a few minutes for data to appear in the Application Signals console after deployment
|
|
132
|
+
|
|
133
|
+
## Completion
|
|
134
|
+
|
|
135
|
+
**Tell the user:**
|
|
136
|
+
|
|
137
|
+
"I've completed the Application Signals enablement for your Python application. Here's what I modified:
|
|
138
|
+
|
|
139
|
+
**Files Changed:**
|
|
140
|
+
- IAM role: Added CloudWatchAgentServerPolicy
|
|
141
|
+
- CloudWatch Observability EKS add-on: Added to the EKS Cluster
|
|
142
|
+
- Kubernetes Deployment: Instrumentation annotation added with inject-python set to true
|
|
143
|
+
|
|
144
|
+
**Next Steps:**
|
|
145
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
146
|
+
2. Review the changes I made using `git diff`
|
|
147
|
+
3. Deploy your infrastructure:
|
|
148
|
+
- For CDK: `cdk deploy`
|
|
149
|
+
- For Terraform: `terraform apply`
|
|
150
|
+
- For CloudFormation: Deploy your stack
|
|
151
|
+
4. After deployment, wait 5-10 minutes for telemetry data to start flowing
|
|
152
|
+
|
|
153
|
+
**Verification:**
|
|
154
|
+
Once deployed, you can verify Application Signals is working by:
|
|
155
|
+
- Opening the AWS CloudWatch Console
|
|
156
|
+
- Navigating to Application Signals → Services
|
|
157
|
+
- Looking for your service (named: {{SERVICE_NAME}})
|
|
158
|
+
- Checking that traces and metrics are being collected
|
|
159
|
+
|
|
160
|
+
**Monitor Application Health:**
|
|
161
|
+
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).
|
|
162
|
+
|
|
163
|
+
**Troubleshooting**
|
|
164
|
+
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).
|
|
165
|
+
|
|
166
|
+
⚠️ **Warning for Django:**
|
|
167
|
+
If your application is built with Django, you must follow [additional steps to prevent startup failures](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html#Application-Signals-troubleshoot-starting).
|
|
168
|
+
|
|
169
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for .NET on AWS Lambda
|
|
2
|
+
|
|
3
|
+
Your task is to modify Infrastructure as Code (IaC) files to enable AWS Application Signals for .NET 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:AWSOpenTelemetryDistroDotNet:6",
|
|
19
|
+
"ap-east-1": "arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
20
|
+
"ap-northeast-1": "arn:aws:lambda:ap-northeast-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
21
|
+
"ap-northeast-2": "arn:aws:lambda:ap-northeast-2:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
22
|
+
"ap-northeast-3": "arn:aws:lambda:ap-northeast-3:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
23
|
+
"ap-south-1": "arn:aws:lambda:ap-south-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
24
|
+
"ap-south-2": "arn:aws:lambda:ap-south-2:796973505492:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
25
|
+
"ap-southeast-1": "arn:aws:lambda:ap-southeast-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
26
|
+
"ap-southeast-2": "arn:aws:lambda:ap-southeast-2:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
27
|
+
"ap-southeast-3": "arn:aws:lambda:ap-southeast-3:039612877180:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
28
|
+
"ap-southeast-4": "arn:aws:lambda:ap-southeast-4:713881805771:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
29
|
+
"ap-southeast-5": "arn:aws:lambda:ap-southeast-5:152034782359:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
30
|
+
"ap-southeast-7": "arn:aws:lambda:ap-southeast-7:980416031188:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
31
|
+
"ca-central-1": "arn:aws:lambda:ca-central-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
32
|
+
"ca-west-1": "arn:aws:lambda:ca-west-1:595944127152:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
33
|
+
"cn-north-1": "arn:aws-cn:lambda:cn-north-1:440179912924:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
34
|
+
"cn-northwest-1": "arn:aws-cn:lambda:cn-northwest-1:440180067931:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
35
|
+
"eu-central-1": "arn:aws:lambda:eu-central-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
36
|
+
"eu-central-2": "arn:aws:lambda:eu-central-2:156041407956:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
37
|
+
"eu-north-1": "arn:aws:lambda:eu-north-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
38
|
+
"eu-south-1": "arn:aws:lambda:eu-south-1:257394471194:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
39
|
+
"eu-south-2": "arn:aws:lambda:eu-south-2:490004653786:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
40
|
+
"eu-west-1": "arn:aws:lambda:eu-west-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
41
|
+
"eu-west-2": "arn:aws:lambda:eu-west-2:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
42
|
+
"eu-west-3": "arn:aws:lambda:eu-west-3:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
43
|
+
"il-central-1": "arn:aws:lambda:il-central-1:746669239226:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
44
|
+
"me-central-1": "arn:aws:lambda:me-central-1:739275441131:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
45
|
+
"me-south-1": "arn:aws:lambda:me-south-1:980921751758:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
46
|
+
"mx-central-1": "arn:aws:lambda:mx-central-1:610118373846:layer:AWSOpenTelemetryDistroDotNet:2",
|
|
47
|
+
"sa-east-1": "arn:aws:lambda:sa-east-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
48
|
+
"us-east-1": "arn:aws:lambda:us-east-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:7",
|
|
49
|
+
"us-east-2": "arn:aws:lambda:us-east-2:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
50
|
+
"us-west-1": "arn:aws:lambda:us-west-1:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
51
|
+
"us-west-2": "arn:aws:lambda:us-west-2:615299751070:layer:AWSOpenTelemetryDistroDotNet:6",
|
|
52
|
+
"us-gov-east-1": "arn:aws-us-gov:lambda:us-gov-east-1:399711857375:layer:AWSOpenTelemetryDistroDotNet:1",
|
|
53
|
+
"us-gov-west-1": "arn:aws-us-gov:lambda:us-gov-west-1:399727141365:layer:AWSOpenTelemetryDistroDotNet: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 .NET Lambda Layer
|
|
169
|
+
|
|
170
|
+
Use the layer name `AWSOpenTelemetryDistroDotNet` 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:AWSOpenTelemetryDistroDotNet:6',
|
|
176
|
+
'ap-east-1': 'arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroDotNet:6',
|
|
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:AWSOpenTelemetryDistroDotNet:6"
|
|
198
|
+
"ap-east-1" = "arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroDotNet:6"
|
|
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:AWSOpenTelemetryDistroDotNet:6
|
|
220
|
+
ap-east-1:
|
|
221
|
+
arn: arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroDotNet:6
|
|
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:AWSOpenTelemetryDistroDotNet:6',
|
|
280
|
+
'ap-east-1': 'arn:aws:lambda:ap-east-1:888577020596:layer:AWSOpenTelemetryDistroDotNet:6',
|
|
281
|
+
// ... (see Region-Specific Layer ARNs section above for complete mapping)
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const dotnetFunction = new lambda.Function(this, 'DotNetFunction', {
|
|
285
|
+
runtime: lambda.Runtime.DOTNET_6,
|
|
286
|
+
handler: 'MyApp::MyApp.Function::FunctionHandler',
|
|
287
|
+
code: lambda.Code.fromAsset('src/MyApp/bin/Release/net6.0/publish'),
|
|
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 .NET 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 AWSOpenTelemetryDistroDotNet 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!"
|