AWSDynamoDB局部索引项集合大小限制
创始人
2024-09-24 22:31:07
0

AWS DynamoDB LSI(局部二级索引)对于每个分区键值最多只能存储10GB的数据,而当LSI项集合大小超过10GB时,查询操作将会失败。为了解决这个问题,我们可以通过以下步骤来进行调整:

1.收集LSI的信息,如分区键和排序键等。

2.使用DynamoDBMapper API或aws-sdk-js创建新的表。

3.将LSI的信息添加到新表的索引中,并将数据导入到新表中。

4.更新原始表中的代码,将查询指向新的表以进行查询操作。

下面是一个示例代码(使用Node.js 和 aws-sdk-js):

const AWS = require('aws-sdk');
const config = {
  region: 'us-east-1', // your AWS region
};
const dynamodb = new AWS.DynamoDB(config);

const sourceTable = 'your-source-table';
const lsiIndexName = 'your-lsi-name';
const newTableName = `${sourceTable}-new`;

// Collect LSI info
const sourceTableRes = await dynamodb.describeTable({ TableName: sourceTable }).promise();
const lsi = sourceTableRes.Table.LocalSecondaryIndexes.find(
  (index) => index.IndexName === lsiIndexName
);
const { KeySchema, Projection } = lsi;

// Create new table
const newTableParams = {
  AttributeDefinitions: sourceTableRes.Table.AttributeDefinitions,
  KeySchema: sourceTableRes.Table.KeySchema,
  TableName: newTableName,
  BillingMode: 'PAY_PER_REQUEST', // This creates a new table with on-demand pricing
  LocalSecondaryIndexes: [
    {
      IndexName: lsiIndexName,
      KeySchema,
      Projection,
    },
  ],
};
await dynamodb.createTable(newTableParams).promise();

// Wait for the new table to be active
while (true) {
  const res = await dynamodb.describeTable({ TableName: newTableName }).promise();
  if (res.Table.TableStatus === 'ACTIVE') break;
  await new Promise((resolve) => setTimeout(resolve, 2000));
}

// Batch write items to the new table
const scanParams = {
  TableName: sourceTable,
  ProjectionExpression: lsi.Projection.NonKeyAttributes,
};
let lastEvaluatedKey;
while (lastEvaluatedKey !== undefined) {
  if (lastEvaluatedKey) scanParams.ExclusiveStartKey = lastEvaluatedKey;

  const res = await dynamodb.scan(scanParams).promise();
  const batchWriteParams = {
    RequestItems: {
      [newTableName]: res.Items.map((item) => ({

相关内容

热门资讯

关于!微信微乐自建房辅助工具,... 关于!微信微乐自建房辅助工具,微乐家乡麻将自建房辅助app(开挂自建房)方法1)微乐家乡麻将自建房辅...
大家学习交流!微信卡五星辅助器... 大家学习交流!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)方法1、很好的工具软件,可以解锁游...
三分钟了解!微乐微信自建房辅助... 三分钟了解!微乐微信自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)工具1、三分钟了解...
一分钟教会你!微乐家乡麻将自建... 一分钟教会你!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)方法1、用户打开应用...
分享实测!微信微乐自建房辅助工... 分享实测!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)器1、起透看视 微信微乐自建房...
重大通报!微乐自建房辅助工具脚... 重大通报!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)app微乐自建房辅助工具脚本破解...
如何分辨真伪!微乐微信自建房辅... 如何分辨真伪!微乐微信自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)技巧1、微乐微信自建房辅...
我来教教你!微乐自建房辅助工具... 我来教教你!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)工具1、玩家可以在微乐家...
重大来袭!微乐自建房辅助工具神... 重大来袭!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)器1、游戏颠覆性的策略玩法,独创...
带你了解!微信卡五星辅助器,微... 带你了解!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)方法1、带你了解!微信卡五星辅助器,...