Error when creating a dynamodb document client aws serverless using aws-xray-sdk,
Asked Answered
U

2

7

I am creating a function which is supposed to write to a dynamodb and I want to generate the trace using aws-xray-sdk.

My function is

    private readonly docClient: DocumentClient = AWS.DynamoDB.DocumentClient()

    async createTodo(todoItem: TodoItem): Promise<TodoItem> {
        await this.docClient.put({
            TableName: this.todosTable,
            Item: todoItem
        }).promise()

        return todoItem
    }

This works very well when I use just the document client from aws sdk as above but because I need the trace when I pass the aws-sdk through the aws-xray-sdk and wants to use the sdk it throws an error. This is how I constuct it.

import * as AWS from 'aws-sdk'
import * as AWSXRay from 'aws-xray-sdk'

const XAWS = AWSXRay.captureAWS(AWS)

then when I do

private readonly docClient: DocumentClient = XAWS.DynamoDB.DocumentClient() I get the error

      TS2339: Property 'DocumentClient' does not exist on type 
'PatchedAWSClientConstructor<ClientConfiguration, typeof DynamoDB>'.

How can I do to eliminate this error or possibly get a document client that can be used for the trace with aws-xray.

Dependencies. "aws-xray-sdk": "^2.2.0", "aws-sdk": "^2.433.0",

Urania answered 13/2, 2020 at 12:17 Comment(1)
I don't know what's wrong with the type definitions; it all looks like a mess to me. I recommend defeating the compiler by bringing in X-Ray with const AWSXRay = require('aws-xray-sdk');, instead of import * as.Estivation
L
5

Using const AWSXRay = require('aws-xray-sdk') worked for me

Lipman answered 23/6, 2022 at 6:57 Comment(0)
A
1

Please use

import AWSXRay from "aws-xray-sdk-core";

This was explained on a similar issue on the AWS X-Ray JS SDK repo: https://github.com/aws/aws-xray-sdk-node/issues/491

Aplomb answered 27/6, 2022 at 21:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.