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の複数のテーブルから一括でデータダウンロード

Posted at

DynamoDBの複数のテーブルから一括でデータダウンロードするバッチファイルを作成したのでメモを残します。

事前準備

AWS CLIの設定

AWS CLIをインストールします。
・IAM作ります。
・aws configure します。
(aws configureの結果が /.aws/credentials に記録されます。後程、awsコマンドを使うのですが、うまくいかなかった時、credentials の中の region が正しく反映されていなかったので手修正したらawsコマンドが正しく実行されました)

pythonのインストール

pythonをインストールします。

csvkitのインストール

in2csvを使うのでcsvkitをインストールします。

pip install csvkit

バッチファイル

次のバッチファイルで一括ダウンロードします。

@echo off
cd /d %~dp0

echo download 1/3
aws dynamodb scan --table-name table1 > result1.json
in2csv result1.json -k Items -e CP932 > result1.csv
echo download 2/3
aws dynamodb scan --table-name table2 > result2.json
in2csv result2.json -k Items -e CP932 > result2.csv
echo download 3/3
aws dynamodb scan --table-name table3 > result3.json
in2csv result3.json -k Items -e CP932 > result3.csv

解説

・"table*"はDynamoDBのテーブル名を入れてください(AWSコンソールで確認)。
・"-k"は次のエラーが出たので付けました:参考リンク

When converting a JSON document with a top-level dictionary element, a key must be specified.

参考リンク

MicrosoftのWindows OSで使用されている機種依存文字を含むシフトJISコードのテキストは「CP932」を指定する必要があります
【bat】Windowsのバッチファイル(*.bat)の書き方自分用まとめ
AWS CLI 出力フォーマットの設定

以上

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?