DynamoDBで発生した障害点の集合


発生した障害点の集合
処理速度の問題の挿入
delete多重削除不可問題
項目削除時に一度だけ削除して一日分のデータを保存し、表をS 3に保存してから、表を削除するという問題を解決しました.
スキャン、クエリー結果のサイズ制限の問題
DynamodBでScan、queryを実行する場合、実行結果は最大1 MBを超えない.1 MBを超えるデータをクエリーするには、クエリー結果に含まれるLastEvaluedKeyが存在するかどうかを確認し、処理のために追加の検索が必要かどうかを確認します.
 @Test
    void dynamoDB_queryTest() {

        int want = 0;
        Map<String, AttributeValue> lastKeyEvaluated = null;
        do {
            ScanRequest scanRequest = new ScanRequest()
                    .withTableName("Test")
                    .withExclusiveStartKey(lastKeyEvaluated);

            ScanResult result = amazonDynamoDb.scan(scanRequest);
            want = want + result.getCount();
            lastKeyEvaluated = result.getLastEvaluatedKey();

            System.out.println(result.getItems());

            Map<String, AttributeValue> key = new HashMap<>();

            for (Map<String, AttributeValue> map : result.getItems()) {
                key.put("id", map.get("id"));

                DeleteItemRequest deleteItemRequest = (new DeleteItemRequest())
                        .withTableName("BeaconHistoryData")
                        .withKey(key);

                amazonDynamoDb.deleteItem(deleteItemRequest);
            }

        } while (lastKeyEvaluated != null);

        System.out.println(want);

    }
グローバルインデックスクエリの問題
DynamodBテーブルをクエリーする場合、テーブル内のパーティションキーではなくグローバルインデックスをクエリーする場合は、Java SDKベース

  • 検索するテーブルを設定し、Tableクラスに含まれるgetIndexにパラメータ値を追加してIndexインスタンスを作成します.

  • 作成したインデックスインスタンスにQuery Specを作成し、必要な値をqueryメソッドで検索します.クエリー生成要素
  •  @Test
        void check_performance(){
    
            long start = System.currentTimeMillis();
    
            DynamoDB dynamoDB = new DynamoDB(amazonDynamoDb);
            Table table = dynamoDB.getTable("Test");
            int [] assetId_list = new int[] {1,2,3,4,5,6,7,8,9,10};
            Index index = table.getIndex("byAssetId");
            for(Integer nowAsset : assetId_list) {
                QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("assetId = :v_id and createdAt between :v_start_at and :v_end_at")
                        .withValueMap(new ValueMap().withInt(":v_id", nowAsset).withString(":v_start_at", "원하는 값").withString(":v_end_at", "원하는 값"));
    
                ItemCollection<QueryOutcome> items = index.query(querySpec);
    
                Iterator<Item> iterator = items.iterator();
                Item item = null;
                Integer count = 0;
    
                List<TestDTO> test_perform = new ArrayList<>();
                Long base_placeId = 0L;
                Long base_timestamp = 0L;
                Long current_timestamp = 0L;
                Long durationTime = 0L;
                while (iterator.hasNext()) {
                    item = iterator.next();
                    count += 1;
                    TestDTO test = TestDTO.builder()
                            // 원하는 값
                            .build();
                 			// 원한는 동작
                    }
    
                }
    
                System.out.println("총 개수는" + count);
                System.out.println("리스트의 길이는  " + test_perform.size());
    
                Iterator<TestDTO> test_list = test_perform.iterator();
    
                while (test_list.hasNext()) {
                    TestDTO temp = test_list.next();
                    System.out.println("머문시간은 " + temp.getStayTime().toString());
                }
            }
            long end = System.currentTimeMillis();
            System.out.println("수행시간: " + (end - start) + " ms");
    
    
        }
    DynamodBの自動削除Lambdaパイプラインエラーの問題の作成
    問題が発生した場合、CloudWatchのログ・グループからエラー・ログのCloudWatchログ・グループのショートカットを表示できます.
    表生成の問題
    Java SDK標準テーブルを作成する場合、すべてのアイテムを作成する必要はありません.テーブルの(パーティション・キー、ソート・キー)、グローバル・インデックスで宣言された(パーティション・キー、ソート・キー)、ローカル・インデックスで宣言された(パーティション・キー、ソート・キー)を作成するだけです.
      table = dynamodb.create_table(
            AttributeDefinitions = [
                {'AttributeName': 'A', 'AttributeType': 'N'}
                , {'AttributeName': 'B', 'AttributeType': 'S'}
                , {'AttributeName': 'C', 'AttributeType': 'S'}
                , {'AttributeName': 'E', 'AttributeType': 'S'}
                , {'AttributeName': 'D', 'AttributeType': 'N'}],
            TableName = "KongPlace_"+str(index)+"_"+str(next_day)[:10], 
            KeySchema = [{'AttributeName': 'E', 'KeyType': 'HASH'}],
            GlobalSecondaryIndexes = [
                {'IndexName': 'byA', 'KeySchema': [{'AttributeName': 'A', 'KeyType': 'HASH'}, {'AttributeName': 'C', 'KeyType': 'RANGE'}], 'Projection': {'ProjectionType': 'ALL'}}
            , {'IndexName': 'byB', 'KeySchema': [{'AttributeName': 'B', 'KeyType': 'HASH'}], 'Projection': {'ProjectionType': 'ALL'}}
            , {'IndexName': 'byD', 'KeySchema': [{'AttributeName': 'D', 'KeyType': 'HASH'}], 'Projection': {'ProjectionType': 'ALL'}}],
            BillingMode = 'PAY_PER_REQUEST')
    参考資料
    https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/developerguide/Scan.html
    https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/developerguide/GSIJavaDocumentAPI.html
    https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/APIReference/API_CreateTable.html
    https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/APIReference/API_Query.html#API_Query_RequestSyntax