Dev1ce
Dev1ce

Reputation: 5954

Is it possible to require child sdk libraries in NodeJs?

I am new to NodeJs, I am trying to require a child library from a parent one,
I am using aws-sdk for most of my tasks, to build clients of the services.

DynamoDb Eg.

var AWS = require("aws-sdk");

AWS.config.update({
  region: "us-west-2"
});

var docClient = new AWS.DynamoDB.DocumentClient();

var table = "Movies";

var year = 2015;
var title = "The Big New Movie";

var params = {
    TableName: table,
    Key:{
        "year": year,
        "title": title
    }
};

docClient.get(params, function(err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});

What I want to do now is implement another service called AWS Xray, without creating its client.
The implementation requires importing aws-xray-sdk-core instead of creating a client object,
Will I need to npm install the library separately or can it be done in the same code as above?

X-Ray snippet is as follows -

var AWSXRay = require('aws-xray-sdk-core');
var AWS = AWSXRay.captureAWS(require('aws-sdk'));

How can I do something like the following, without separate npm installation for aws-xray-sdk-core?

var AWSXRay = require('aws-sdk/aws-xray-sdk-core');

Upvotes: 1

Views: 56

Answers (1)

Paresh Barad
Paresh Barad

Reputation: 1609

As per git repo and AWS document AWSJavaScriptSDK, XRay() class already exist in aws-sdk master package so you can access it without aws-xray-sdk-core

var xray = new AWS.XRay();

Upvotes: 2

Related Questions