LoginSignup
0
0

More than 3 years have passed since last update.

ソートキーのあるDynamoDBのテーブルにCSVファイルを一括アップロードする方法

Posted at

したかったこと

  • DynamoDBに一括でCSVファイルの内容をアップロードしたい
  • テーブルにはソートキーを設定したい

プライマリキーだけの場合の記事はいっぱいあったが、ソートキーのあるものはみなかった。

方法

CloudFormationに「CSVをDynamoDBに入れる」スタックを作成

以下の一括アップロードの方法をベースにして、テンプレートファイルの中身だけ少し変える。

  • 一括アップロードの方法はここが参考になった。
  • ソートキーのあるテーブルの作成方法はここが参考になった

テンプレートファイル

テンプレートファイルにソートキーの情報を足す。
データ型はStringなら "S" にする。

 "Resources": {
        "DynamoDBTable":{
            "Type": "AWS::DynamoDB::Table",
            "Properties":{
                "TableName": {"Ref" : "DynamoDBTableName"},
                "BillingMode": "PAY_PER_REQUEST",
                "AttributeDefinitions":[
                    {   
                        "AttributeName": "【パーティションキー名】",
                        "AttributeType": "【データ型】" 
                    },  
                    {   
                        "AttributeName": "【ソートキー名】",
                        "AttributeType": "【データ型】" 
                    }   
                ],  
                "KeySchema":[
                    {   
                        "AttributeName": "【パーティションキー名】",
                        "KeyType": "HASH"
                    },  
                    {   
                        "AttributeName": "【ソートキー名】",
                        "KeyType": "RANGE"
                    }   
                ],  
                "Tags":[
                    {   
                        "Key": "Name",
                        "Value": {"Ref" : "DynamoDBTableName"}
                    }   
                ]   
            }   
        },  

備考

bucket already existエラーが出た
-> 一意でなければならないよう
スタックを削除して、一意なバケット名を入れて、もう一度作り直した。

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