错误:获取状态锁失败:ConditionalCheckFailedException:条件请求失败:ProvisionedThroughputExceededException:速率超限
Error: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed: ProvisionedThroughputExceededException: Rate exceeded
ID: terraform/state-lock-dynamodb-throttling
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform 1.5.0 | active | — | — | — |
| Terraform 1.6.0 | active | — | — | — |
| Terraform 1.7.0 | active | — | — | — |
根因分析
用于状态锁定的 DynamoDB 表因请求速率过高而受到限流,超出了预置的读写容量。
English
DynamoDB table used for state locking is experiencing throttling due to high request rates, exceeding its provisioned read/write capacity.
官方文档
https://developer.hashicorp.com/terraform/language/settings/backends/s3#dynamodb-table-configuration解决方案
-
增加 DynamoDB 表的预置读写容量单元以处理峰值负载。如果工作负载不可预测,切换到按需容量模式。
-
通过将 terraform 命令包装在带有指数退避的 bash 脚本中,实现客户端重试逻辑。
-
在高峰时段减少 terraform apply/plan 操作的频率,或错开多个 CI/CD 管道以避免并发锁尝试。
无效尝试
常见但无效的做法:
-
90% 失败
The lock acquisition failed due to throttling, not because the lock is held. Force-unlock doesn't address the throughput issue.
-
80% 失败
Deleting the table removes all state lock items but also any existing locks. Recreating with default settings still has low throughput.
-
95% 失败
Terraform's retry mechanism is for provider operations, not for state lock acquisition. The lock mechanism is internal and not configurable.