Description
With TracingConfig.Mode set to Active, Lambda sends traces for sampled requests to X-Ray. PassThrough forwards the trace context to downstream calls.
Potential impact
Without traces, it can be difficult to locate a delay or error between the function and a downstream service.
Remediation
If you need automatic tracing, set TracingConfig.Mode: Active and grant X-Ray write permissions to the execution role. Check for sampled traces after invocation. Instrument the call to the target function if you need its timing.
Examples
Use a Create or Update request to check the downstream trace. Only those paths in the Node.js 22 handler invoke the target through the AWS SDK for JavaScript v3. Delete returns success immediately. Supply the target and invoke permission, and log only the request fields you need.
Before
AWSTemplateFormatVersion: '2010-09-09'
Description: Lambda function with cfn-response.
Resources:
primer:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs22.x
Role: arn:aws:iam::123456789012:role/lambda-role
Handler: index.handler
Code:
ZipFile: |
var { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda')
var response = require('cfn-response')
exports.handler = function(event, context) {
console.log("REQUEST RECEIVED:\n" + JSON.stringify(event))
// For Delete requests, immediately send a SUCCESS response.
if (event.RequestType == "Delete") {
response.send(event, context, "SUCCESS")
return
}
var responseStatus = "FAILED"
var responseData = {}
var functionName = event.ResourceProperties.FunctionName
var lambda = new LambdaClient({})
lambda.send(new InvokeCommand({ FunctionName: functionName }), function(err, invokeResult) {
if (err) {
responseData = {Error: "Invoke call failed"}
console.log(responseData.Error + ":\n", err)
}
else responseStatus = "SUCCESS"
response.send(event, context, responseStatus, responseData)
})
}
Description: Invoke a function during stack creation.
TracingConfig:
Mode: PassThrough
After
AWSTemplateFormatVersion: '2010-09-09'
Description: Lambda function with cfn-response.
Resources:
primer:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs22.x
Role: arn:aws:iam::123456789012:role/lambda-role
Handler: index.handler
Code:
ZipFile: |
var { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda')
var response = require('cfn-response')
exports.handler = function(event, context) {
console.log("REQUEST RECEIVED:\n" + JSON.stringify(event))
// For Delete requests, immediately send a SUCCESS response.
if (event.RequestType == "Delete") {
response.send(event, context, "SUCCESS")
return
}
var responseStatus = "FAILED"
var responseData = {}
var functionName = event.ResourceProperties.FunctionName
var lambda = new LambdaClient({})
lambda.send(new InvokeCommand({ FunctionName: functionName }), function(err, invokeResult) {
if (err) {
responseData = {Error: "Invoke call failed"}
console.log(responseData.Error + ":\n", err)
}
else responseStatus = "SUCCESS"
response.send(event, context, responseStatus, responseData)
})
}
Description: Invoke a function during stack creation.
TracingConfig:
Mode: Active