aws sdk에서 대부분은 aws-sdk/client-(서비스 이름) 식으로 이름이 작명되어 있지만, storage, dynamodb의 경우 client 대신 lib을 가진 패키지가 추가로 존재한다.
@aws-sdk/client-dynamodb의 경우 공식 API 문서에서 다음과 같이 패키지를 소개하고 있다.
The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types.
input과 output이 자바스크립트 타입으로 변환되어 lib 모듈에 비해 간단히 사용을 할 수 있다는 이야기를 하고 있다.
둘의 동작 차이를 확인하기 위해 QueryCommand를 통해 자세히 확인해보자.
/*
* DB 데이터로 반환되는 Item은 다음과 같다 가정
* {
* OriginCountry: Ethiopia,
* roastDate: 2023-05-02,
* CoffeeBeanID: 123
* }
* @aws-sdk/lib-dynamodb를 사용한 경우
*/
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { QueryCommand, DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
export const main = async () => {
const command = new QueryCommand({
TableName: "CoffeeCrop",
KeyConditionExpression:
"OriginCountry = :originCountry AND RoastDate > :roastDate",
ExpressionAttributeValues: {
":originCountry": "Ethiopia",
":roastDate": "2023-05-01",
},
ConsistentRead: true,
});
const {Items} = await docClient.send(command);
/*
[{
OriginCountry: Ethiopia,
roastDate: 2023-05-02,
CoffeeBeanID: 123
}]
*/
console.log(Items)
return response;
};
/*
* @aws-sdk/client-dynamodb를 사용한 경우
*/
const client = new DynamoDBClient({});
export const main = async () => {
const command = new QueryCommand({
TableName: "CoffeeCrop",
KeyConditionExpression:
"OriginCountry = :originCountry AND RoastDate > :roastDate",
ExpressionAttributeValues: {
":originCountry": {
S: "Ethiopia"
},
":roastDate": {
S: "2023-05-01"
},
},
ConsistentRead: true,
});
const {Items} = await client.send(command);
/*
[{
OriginCountry: {
"S": Ethiopia
},
roastDate: {
"S": 2023-05-02
},
CoffeeBeanID: {
"N": 123
}
}]
*/
console.log(Items)
return response;
};
import { Upload } from "@aws-sdk/lib-storage";
import { S3Client, S3 } from "@aws-sdk/client-s3";
try {
const parallelUploads3 = new Upload({
client: new S3({}) || new S3Client({}),
params: { Bucket, Key, Body },
tags: [
/*...*/
], // optional tags
queueSize: 4, // optional concurrency configuration
partSize: 1024 * 1024 * 5, // optional size of each part, in bytes, at least 5MB
leavePartsOnError: false, // optional manually handle dropped parts
});
parallelUploads3.on("httpUploadProgress", (progress) => {
console.log(progress);
});
await parallelUploads3.done();
} catch (e) {
console.log(e);
}
Reference:
https://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v3/developer-guide/dynamodb-example-dynamodb-utilities.html#dynamodb-example-document-client-query
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-storage/