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

harisu
  • 1,376
  • 8
  • 17
  • 10
    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`. – Mike Patrick Feb 13 '20 at 22:44

2 Answers2

5

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

Silas Jimmy
  • 51
  • 1
  • 2
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

Nathaniel Ruiz
  • 484
  • 6
  • 12