Node.js 启用aws xray serverless.yml
我试图通过以下方式为所有lambda功能启用aws X射线: serverless.ymlNode.js 启用aws xray serverless.yml,node.js,typescript,amazon-web-services,aws-xray,Node.js,Typescript,Amazon Web Services,Aws Xray,我试图通过以下方式为所有lambda功能启用aws X射线: serverless.yml provider: tracing: lambda: true apiGateway: true name: aws runtime: nodejs8.10 stage: ${opt:stage, 'dev'} region: ${opt:region, 'ca-central-1'} 服务台 import*作为AWS从“AWS sdk”导入 从“aws X射线s
provider:
tracing:
lambda: true
apiGateway: true
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ca-central-1'}
服务台
import*作为AWS从“AWS sdk”导入
从“aws X射线sdk”导入*作为AWSXRay
const XAWS=AWSXRay.captureAWS(AWS)
const docClient:DocumentClient=new XAWS.DynamoDB.DocumentClient()
const s3=new XAWS.s3({signatureVersion:'v4'})
在sls部署之后
我得到以下错误:
An error occurred: <some_lambda funcion> - The provided execution role does not have permissions to call PutTraceSegments on XRAY (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 364243f8-8847-48ef-87ad-75da2537e7f7).
还是一样的问题
我将非常感谢任何帮助,因为我不知道为什么这是一个问题,特别是因为我有另一个项目与跟踪启用完全相同的方式没有问题
package.json:
{
"name": "mini-twitter",
"version": "1.0.0",
"description": "Serverless Mini-Twitter app",
"dependencies": {
"aws-xray-sdk": "^2.2.0",
"source-map-support": "^0.5.11",
},
"devDependencies": {
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.14.4",
"aws-sdk": "^2.433.0",
"serverless-iam-roles-per-function": "^1.0.4",
"serverless-webpack": "^5.2.0",
"ts-loader": "^5.3.3",
"typescript": "^3.4.1",
}
}
似乎
sls deploy
命令没有向IAM角色添加X射线权限。您是否尝试过手动将其添加到中
转到AWS控制台,导航到IAM,找到与部署相对应的角色,并将AWSXRayWriteOnly访问
策略附加到该角色,查看其是否有效。如果权限
- Effect: Allow
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"
您添加的不是全局性的,那么您还应该确保您在lambda中提到的
函数也应该具有权限。ie如果您使用的插件类似于serverless iam roles per function
这对我的案例有效,但我仍然不知道问题的确切原因,因为其他人在没有它的情况下工作。您需要安装插件: 就像Gareth McCumskey的评论(谢谢!) 只需使用:
serverless plugin install --name serverless-plugin-tracing
或者手动操作:
npm install --save-dev serverless-plugin-tracing
并在serverless.yml上启用它:
plugins:
- serverless-plugin-tracing
现在,您的文件如下所示:
provider:
name: aws
stage: test
tracing: true # enable tracing
iamRoleStatements:
- Effect: "Allow" # xray permissions (required)
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"
plugins:
- serverless-plugin-tracing
更多信息:
一个提示。只需使用
serverless plugin install--name serverless plugin tracing
,它就能为您完成一切
provider:
name: aws
stage: test
tracing: true # enable tracing
iamRoleStatements:
- Effect: "Allow" # xray permissions (required)
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"
plugins:
- serverless-plugin-tracing