Skip to content

Commit e4f369f

Browse files
authored
CCM-14206 - Enabled configuration of X-Ray tracing for lambdas (#166)
1 parent 97b3624 commit e4f369f

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

infrastructure/terraform/modules/lambda/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| <a name="input_description"></a> [description](#input\_description) | Description of the Lambda | `string` | n/a | yes |
1919
| <a name="input_enable_dlq_and_notifications"></a> [enable\_dlq\_and\_notifications](#input\_enable\_dlq\_and\_notifications) | Create an SQS Queue and on-failure destination to be used as the Lambda's Dead Letter Queue and notifications | `bool` | `false` | no |
2020
| <a name="input_enable_lambda_insights"></a> [enable\_lambda\_insights](#input\_enable\_lambda\_insights) | Enable the lambda insights layer, this must be disabled for lambda@edge usage | `bool` | `true` | no |
21+
| <a name="input_enable_xray_tracing"></a> [enable\_xray\_tracing](#input\_enable\_xray\_tracing) | Enable AWS X-Ray active tracing for the Lambda function. | `bool` | `false` | no |
2122
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
2223
| <a name="input_filter_pattern"></a> [filter\_pattern](#input\_filter\_pattern) | Filter pattern to use for the log subscription filter | `string` | `""` | no |
2324
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "aws_iam_role_policy_attachment" "xray" {
2+
count = var.enable_xray_tracing ? 1 : 0
3+
4+
role = aws_iam_role.main.name
5+
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
6+
}

infrastructure/terraform/modules/lambda/lambda_function.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ resource "aws_lambda_function" "main" {
4949
}
5050
}
5151

52+
dynamic "tracing_config" {
53+
for_each = var.enable_xray_tracing ? [1] : []
54+
content {
55+
mode = "Active"
56+
}
57+
}
58+
5259
dynamic "vpc_config" {
5360
for_each = var.vpc_config != null ? [""] : []
5461

infrastructure/terraform/modules/lambda/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ variable "enable_lambda_insights" {
268268
default = true
269269
}
270270

271+
variable "enable_xray_tracing" {
272+
type = bool
273+
description = "Enable AWS X-Ray active tracing for the Lambda function."
274+
default = false
275+
}
276+
271277
variable "lambda_at_edge" {
272278
type = bool
273279
description = "Whether this Lambda is a Lambda@Edge function"

0 commit comments

Comments
 (0)