카테고리 없음

DynamoDB 사용법

person456 2024. 7. 15. 22:06

테이블 생성

 

aws dynamodb create table \

    --table-name Chatroom \    // 테이블 이름

    --attribute-definitions \ // 테이블에 사용할 컬럼을 지정하는 것. 각 속성은 이름과 데이터 타입을 지정해야함.

        AttributeName=id,AttributeType=S \

        AttributeName=date,AttributeType=S \

    --key-schema \    // key에 대한 schema 지정.  즉, 테이블의 기본키인 것임.

        AttributeName=id,KeyType=HASH \

        AttributeName=date,KeyType=RANGE \

    --provisioned-throughput \   프로비저닝된 입력과 출력에 대한 값. 1~40000까지 가능

        ReadCapacityUnits=5,WriteCapacityUnits=5

 

 

테이블에 아이템 삽입

aws dynamodb put-item \

--table-name Chatroom \

--item '{

"Chatroom_id": {"S": "unique-chatroom-id-1"},

"chatroom_name": {"S": "Chatroom 1"},

"sender": {"S": "user1"},

"receiver": {"S": "user2"},

"content": {"S": "Hello!"},

"date": {"S": "2023-07-15T12:34:56Z"}

}'

 

테이블에 아이템 수정

aws dynamodb update-item \

--table-name Chatroom \

--key '{

"Chatroom_id": {"S": "unique-chatroom-id-1"},

"date": {"S": "2023-07-15T12:34:56Z"} }' \

--update-expression "SET content = :newContent" \

--expression-attribute-values '{ ":newContent": {"S": "Hello, World!"}

}'

 

테이블에 아이템 삭제

aws dynamodb delete-item \

--table-name Chatroom \

--key '{

"Chatroom_id": {"S": "unique-chatroom-id-1"},

"date": {"S": "2023-07-15T12:34:56Z"}

}'

 

테이블에 아이템 조회

aws dynamodb query \

--table-name Chatroom \

--key-condition-expression "Chatroom_id = :id" \

--expression-attribute-values '{

":id": {"S": "unique-chatroom-id-1"}

}'

 

 

 

AttributeType 

S = String

B = Binary

N = Number

 

KeyType

HASH = 파티션 키로 사용될 속성

RANGE = 소트할 기준

 

 

--provisioned-throughput

Read, Write에 대한 처리량 Units 수 지정 ( 1 ~ 40000)

숫자가 높을수록 성능이 좋지만 그만큼 돈을 더 가져감