What's the difference? #5634
-
mostly every service client in aws-sdk v3 can be imported/used two ways what's the difference what i know is little difference like the second one can be used like v2 except for some difference |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @tahamansoor , The main differences between the two import methods is syntax and structure. Both achieve similar outcomes, but they cater to different coding styles. When you use: import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; You're taking advantage of JS SDK v3's modular approach. Here, you directly import the client and then utilize it to send commands. For instance: import { DynamoDBClient, PutItemCommand} from '@aws-sdk/client-dynamodb'; // adding here each command you want to use.
const client = new DynamoDBClient(/* config */);
client.send(new PutItemCommand(/* command parameters */)); On the other hand, the following import: import { DynamoDB } from '@aws-sdk/client-dynamodb'; is more closely aligned with the v2 SDK's coding style, offering a familiar interface for those who are transitioning from v2. In this case, you would use the service class directly, like so: import { DynamoDB } from '@aws-sdk/client-dynamodb';
const dynamoDB = new DynamoDB(/* config */);
dynamoDB.putItem(/* params */); Hope this clarifies the differences. |
Beta Was this translation helpful? Give feedback.
Hi @tahamansoor ,
The main differences between the two import methods is syntax and structure. Both achieve similar outcomes, but they cater to different coding styles.
When you use:
You're taking advantage of JS SDK v3's modular approach. Here, you directly import the client and then utilize it to send commands. For instance:
On the other hand, the following import: