# Error: Error acquiring the state lock

AWS error fixes · Updated 17 November 2026

**Short answer:** Another Terraform run holds the lock on this state, or a previous run was killed before it released it. The error prints the lock's ID, who took it and when. If that run is still going, wait. If it's definitely dead (a cancelled CI job, a closed laptop), release it with terraform force-unlock LOCK_ID. If the error mentions ResourceNotFoundException or AccessDenied instead, the lock table or lock file permissions are misconfigured rather than locked.

## Read the lock info

```
Error: Error acquiring the state lock

Error message: operation error DynamoDB: PutItem, https response error StatusCode: 400,
ConditionalCheckFailedException: The conditional request failed
Lock Info:
  ID:        6f1c2a9e-2b7d-4c1e-9a55-0d3e8b1f4a21
  Path:      my-tf-state/prod/network.tfstate
  Operation: OperationTypeApply
  Who:       runner@ip-10-0-1-23
  Version:   1.9.8
  Created:   2026-11-17 09:12:44.123 +0000 UTC
```

`Who` and `Created` tell you whether this is a colleague's apply in progress, a CI job, or a stale lock from hours ago. With S3 native locking the message refers to a `.tflock` object instead of DynamoDB, but the Lock Info block is the same.

## Release a stale lock safely

1. Confirm the holder isn't running: check the CI job, ask the person named in `Who`.

2. Release it from the same working directory and backend configuration:

   ```
   terraform force-unlock 6f1c2a9e-2b7d-4c1e-9a55-0d3e8b1f4a21
   ```

3. Run `terraform plan` before applying. A run killed mid-apply may have changed resources without writing state, so expect drift.

As a last resort when Terraform itself can't unlock, the DynamoDB lock is an item whose `LockID` is the bucket/key path; deleting that item releases it. Do this only with the same certainty as `force-unlock`.

## When it isn't really locked

| Error message contains | Cause |
|---|---|
| `ResourceNotFoundException: Requested resource not found` | The `dynamodb_table` named in the backend doesn't exist in that Region, or the backend's Region is wrong |
| `AccessDeniedException` on `dynamodb:PutItem` | The role lacks `GetItem`, `PutItem` and `DeleteItem` on the lock table |
| `AccessDenied` on the `.tflock` object | With `use_lockfile`, the role needs `s3:PutObject` and `s3:DeleteObject` on the lock file key as well as the state key |
| `ExpiredToken` or credential errors | Credentials expired; see [no valid credential sources](https://cloudconsole.dev/errors/terraform-no-valid-credential-sources) |

The lock table needs a partition key named `LockID` of type String.

## DynamoDB locking or S3 lockfile

Since Terraform 1.10 the S3 backend can lock with a lock file in the same bucket (`use_lockfile = true`), using S3 conditional writes, and DynamoDB-based locking is deprecated in newer versions. You can enable both during migration. Either way:

- Don't run applies against the same state concurrently from CI and laptops; serialise pipeline runs per state.
- Use `-lock-timeout=5m` in CI so a short overlap waits instead of failing.
- Never use `-lock=false` on shared state; two concurrent writes can corrupt it. Keep bucket versioning on so you can recover an older state version.

## Questions

### How do I unlock Terraform state stuck after a cancelled run?

Make sure no run is still active, then run terraform force-unlock with the lock ID from the error, from the same working directory and backend configuration.

### Why does Terraform say ConditionalCheckFailedException when acquiring the lock?

That's DynamoDB reporting that a lock item already exists for this state, meaning another run holds or left the lock.

### Do I still need DynamoDB for Terraform state locking on S3?

Not with Terraform 1.10 or later, which can lock using an S3 lock file (use_lockfile = true). DynamoDB locking is deprecated in newer versions.

## When this happens away from your desk

A stuck lock blocks every infrastructure change until someone frees it. CloudConsole, a phone app for AWS, is being built to show alarms, logs and resources on your phone, so you can follow the incident the change was meant to fix.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Conditional writes in Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-writes.html)
- [Condition expressions in DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html)

## Related

- [Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found](https://cloudconsole.dev/errors/terraform-no-valid-credential-sources)
- [ConditionalCheckFailedException: The conditional request failed](https://cloudconsole.dev/errors/dynamodb-conditionalcheckfailed)
- [ResourceNotFoundException: Requested resource not found (DynamoDB)](https://cloudconsole.dev/errors/dynamodb-resourcenotfound)
- [S3 AccessDenied: Access Denied when calling an S3 operation](https://cloudconsole.dev/errors/s3-access-denied)
- [aws dynamodb delete-item](https://cloudconsole.dev/cli/dynamodb-delete-item)
- [AccessDeniedException: User is not authorized to perform this action because no identity-based policy allows it](https://cloudconsole.dev/errors/accessdenied-no-identity-based-policy-allows)

---

Source: https://cloudconsole.dev/errors/terraform-error-acquiring-state-lock

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
