Reputation: 11
package versions:
I have been writing custom helper classes for AWS services and have the following configuration:
Base Helper Class (common funcs and what not)
{{AWS_SERVICE}} Class Extends Base Helper
like so:
export class S3Helper extends BaseHelper {
private client: S3Client;
private httpHelper: HTTPHelper;
/**
* Creates a new instance of S3Helper.
* @param logger {ILogger} - Injected logger.
* @param client {S3} - Optional injected S3 client. If not supplied, a new S3 client will be created.
* @param options {ClientConfiguration} - Optional S3 configuration. Only used if the service parameter is not supplied.
*/
constructor(logger: ILogger, client?: S3Client, options: S3ClientConfig = {}, httpHelper?: HTTPHelper) {
super(logger);
this.client = client || AWSXray.captureAWSv3Client(new S3Client(options));
this.httpHelper = httpHelper || new HTTPHelper(logger);
}
}
All Lambda functions have xray tracing enabled so that isn't my issue. When deployed and running on Node 18.x, here's the issue when (in this case) reading from Param store.
{
"level": "ERROR",
"msg": "segment.addNewSubsegmentWithoutSampling is not a function",
"errorName": "TypeError",
"errorMsg": "segment.addNewSubsegmentWithoutSampling is not a function",
"errorStack": "TypeError: segment.addNewSubsegmentWithoutSampling is not a function\n at /var/task/index.js:6948:30\n at /var/runtime/node_modules/@aws-sdk/middleware-content-length/dist-cjs/index.js:26:16\n at /var/runtime/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:13:12\n at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22\n at async SSMHelper.GetParameter (/var/task/index.js:890311:20)\n at async Runtime.handler (/var/task/index.js:906957:27)"
}
I've tried multiple different versions of AWS SDK, XRAY SDK, different combinations, all that. Everything worked when old legacy code was on AWS SDK v2 and used captureAWSClient
Upvotes: 0
Views: 521
Reputation: 81
Please ensure that all lambda layers containing the AWS X-Ray Node SDK are using the same version (>= 3.4.0 where this API was introduced). See this GitHub issue for more details and resolution for this issue.
Upvotes: 1