gpt4 book ai didi

amazon-web-services - AWS lambda nodejs 在使用 X-RAY 时显示错误

转载 作者:行者123 更新时间:2023-12-03 23:14:57 29 4
gpt4 key购买 nike

我有以下代码:

var AWSXRay = require('aws-xray-sdk');
var AWS = AWSXRay.captureAWS(require('aws-sdk'));
const client = AWSXRay.captureAWSClient(new AWS.DynamoDB.DocumentClient({region : 'eu-west-1'}));
exports.handler = function(event, context, callback) {

AWSXRay.captureFunc('annotations', function(subsegment){
subsegment.addAnnotation('User', **);
subsegment.addAnnotation('Name', **);
});

var params = {
TableName: "****",
** all params **
};
client.query(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else{
callback(null,data);
}
});
}

执行上述代码时,抛出以下错误:
Response:
{
"errorMessage": "service.customizeRequests is not a function",
"errorType": "TypeError",
"stackTrace": [
"Object.<anonymous> (/var/task/index.js:5:24)",
"Module._compile (module.js:570:32)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)",
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)"
]
}

以下是函数的日志:
Function Logs:
START RequestId: Version: $LATEST
module initialization error: TypeError
at Object.captureAWSClient (/var/task/node_modules/aws-xray-sdk-core/lib/patchers/aws_p.js:55:11)
at Object.<anonymous> (/var/task/index.js:5:24)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
END

我应该如何解决这个问题?

最佳答案

在此处发布短期解决方法以获得更好的可见性。

const ddbClient = AWSXray.captureAWSClient(new AWS.DynamoDB({...}));
const client = new AWS.DynamoDB.DocumentClient({
service: ddbClient
});
client.service = ddbClient;

在这里查看一些推理和讨论 https://forums.aws.amazon.com/thread.jspa?messageID=821510&#821510

关于amazon-web-services - AWS lambda nodejs 在使用 X-RAY 时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53066117/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com