如何处理 dynamodb WCU 限制?当你超过限制时它会排队吗?

How to handle dynamodb WCU limitation ? is it queued when you go above the limit?

我需要用大约 10k 项来填充数据库,我不需要着急并且 can/want 保持在 25wcu 免费计划以下。 大约需要 6.5 分钟(10000 个请求/25 个请求/秒)。

问题来了。 我将循环 json 来喂养基地 我必须自己处理第二个请求的数量还是我可以推送到最大,它将排队?

我读到,当我超过限制时,我可能只会收到一条错误消息(400?),我可以粗暴地重试失败的请求(最终导致更多失败)直到我的 10k 项被放入数据库吗?

tldr; => 知道有一个限制 calls/sec

最好 way/strategy 喂养基地

ps:如果重要的话,它是来自 lambda idk 的 运行。

除非你经常这样做,否则你的计算有点偏差,因为AWS实际上让你爆了一点(docs):

DynamoDB provides some flexibility in your per-partition throughput provisioning by providing burst capacity. Whenever you're not fully using a partition's throughput, DynamoDB reserves a portion of that unused capacity for later bursts of throughput to handle usage spikes.

DynamoDB currently retains up to 5 minutes (300 seconds) of unused read and write capacity. During an occasional burst of read or write activity, these extra capacity units can be consumed quickly—even faster than the per-second provisioned throughput capacity that you've defined for your table.

因为 300 (seconds) * 25 (WCU) = 7500 这会给您留下大约 7.5k 个项目,直到它真正节流。

之后仅通过稍后重试来响应 ProvisionedThroughputExceeded 错误是可以的 - 但请确保 在重试之间添加一个小延迟 (例如 1 秒),如您所知新的 WCU 流入令牌桶需要时间。立即重试并攻击 API 不是使用该服务的好方法,可能看起来像 DoS 攻击。

您也可以在Batches中写入项目以减少网络请求量,因为网络吞吐量在 Lambda 中也是有限的。这使得处理 ProvisionedThroughputExceeded 错误稍微麻烦一些,因为您需要检查哪些项目未能写入的响应,但可能是净正数。