我正在尝试通过以下方式为所有lambda函数启用aws-xray:
serverless.yml
provider:
tracing:
lambda: true
apiGateway: true
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ca-central-1'}service.ts
import * as AWS from 'aws-sdk'
import * as AWSXRay from 'aws-xray-sdk'
const XAWS = AWSXRay.captureAWS(AWS)
const docClient: DocumentClient = new XAWS.DynamoDB.DocumentClient()
const s3 = new XAWS.S3({signatureVersion: 'v4'})在sls deploy之后,我得到以下错误:
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).我不确定问题出在哪里。我还尝试使用以下命令进行部署:
iamRoleStatements:
- Effect: Allow
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"仍然是同样的问题。
我将非常感谢任何帮助,因为我不知道为什么这是一个问题,特别是因为我有另一个项目与跟踪启用完全相同的方式没有问题!
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",
}
}发布于 2020-03-27 18:21:36
您需要安装插件:
喜欢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更多信息:https://serverless.com/plugins/serverless-plugin-tracing/
发布于 2020-02-14 22:37:31
如果权限
- Effect: Allow
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"你添加的不是全局的,那么你也应该确保你在lambda中提到的<some_lambda funcion>函数也应该有权限。也就是说,如果你使用像serverless-iam-roles-per-function这样的插件,这对我来说是可行的,但是我仍然不知道问题的确切原因,因为其他人在没有它的情况下工作。
发布于 2019-08-31 02:59:38
看起来sls deploy命令没有将X射线权限添加到IAM角色。你试过手动添加吗?
转到亚马逊网络服务控制台,导航到IAM,找到与部署相对应的角色,并将AWSXrayWriteOnlyAccess策略附加到该角色,看看它是否有效。
https://stackoverflow.com/questions/57618014
复制相似问题