gpt4 book ai didi

node.js - 启用 aws-xray serverless.yml

转载 作者:太空宇宙 更新时间:2023-11-04 01:25:40 27 4
gpt4 key购买 nike

我尝试通过以下方式为所有 lambda 函数启用 aws-xray:

无服务器.yml

provider:
tracing:
lambda: true
apiGateway: true

name: aws
runtime: nodejs8.10

stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ca-central-1'}

服务.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部署之后我收到以下错误:

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",
}
}

最佳答案

您需要安装插件:

点赞 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/

关于node.js - 启用 aws-xray serverless.yml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57618014/

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