0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DynamoDBのクリーンとコピー

Last updated at Posted at 2022-06-23

はじめに

DynamoDBのクリーンとコピーの仕方について、簡単に説明

目次

  • テーブルのクリーン
  • テーブルのコピー
  • 最後に

TableのCleanUp

Scan + Delete Item

①すべてのデータをScan
②1件ずつ削除

 結果:遅い、コスト高い

aws dynamodb scan --table-name myTable
aws dynamodb delete-item --table-name myTable --key '{ "user_id": { "N": "1" }}'

※scanはデフォルトでは、1度に取得できるのは最大1MB

Drop Table + Create Table

①テーブル削除
②テーブル作成

 結果:早い、テーブルの再設定が面倒

aws dynamodb create-table \
    --table-name Music \
    --attribute-definitions \
        AttributeName=Artist,AttributeType=S \
        AttributeName=SongTitle,AttributeType=S \
    --key-schema \
        AttributeName=Artist,KeyType=HASH \
        AttributeName=SongTitle,KeyType=RANGE \
    --provisioned-throughput \
        ReadCapacityUnits=5,WriteCapacityUnits=5 \
    --table-class STANDARD

aws dynamodb delete-table --table-name Music 

TableのCopy

backap+restore

①バックアップ
②リストア※1
※1 リストア時、新しいテーブルで作成される
  手動でTTLやメトリクス、ロール等の設定が発生

 結果:早い、キャパシティを利用しない

Scan + Write Item

①すべてのデータをScan
②1件ずつ追加

 結果:遅い、コスト高い

aws dynamodb scan --table-name Music  
aws dynamodb put-item \
    --table-name Music  \
    --item \
        '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "1"}}'

※scanはデフォルトで最大100件のため、ページング等が必要

DataPipeLine(EMR)でexport+import

①import:DynamoDB→EMR→S3
②export:S3→EMR→DynamoDB

 結果:早い(バックアップ用途では、AWS非推奨)

最後に

テーブルのクリアやコピーは他にもあるとは思いますが、メジャーなものを記載しました。
imtem数が少ないテーブルであれば、scanしてクリアやコピーしても問題ないと思います。
メリット、デメリットを把握した上で使用できたらと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?