# S3 backend state lock won't release

**URL:** <https://discuss.hashicorp.com/t/s3-backend-state-lock-wont-release/21367>\
**Category:** Terraform\
**Created:** [February 24, 2021, 6:58pm UTC](https://discuss.hashicorp.com/t/s3-backend-state-lock-wont-release/21367 "2021-02-24T18:58:43Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![metacarina](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/metacarina/32/17535_2.png) [@metacarina](https://discuss.hashicorp.com/u/metacarina)\
**Post date:** [February 25, 2021, 1:51pm UTC](https://discuss.hashicorp.com/t/s3-backend-state-lock-wont-release/21367/4 "2021-02-25T13:51:36Z")

</div>

##Solution

I have a quite complex environment, and I have no console access to this account. The LockID field in the dynamoDB table was not what I expected. I could not find these specific instructions anywhere, so I thought I would describe how to actually do this using the CLI for anyone else who may get stuck with state lock hangups.

I viewed the lock table in in my config first, then I verified it existed in the AWS account I was currently using. The profile is my named AWS CLI profile for this project. If you only have one AWS CLI account configured, you can leave off the `--profile=<your_profile>` command from all of these and probably skip this validation step.

`aws dynamodb list-tables --profile=<your_profile>`

Then I listed all items in the table. I had quite a few states in my table because of my complex env.

`aws dynamodb scan --table-name <your_table> --profile=<your_profile>`

The LockID for deleting the state is not the lockID shown in the output telling you that your state was locked. My LockID, which is what I needed to put in the command below, looked like a path to a terraform.tfstate file. What the error message showed me as the LockID is a different field, just called `ID`. Currently locked states will have an `Info` attribute that has that ID so you can confirm you are targeting the correct state. To verify that more easily:

```
aws dynamodb get-item \
--table-name <your_lock_table> \
--key '{
      "LockID": {"S":"<lock_id_discovered_during_previous_step>"}
  }' \
--profile=<your_profile>

```

Once you are totally sure you are targeting the right state, removing the entry cleared the lock.

```
aws dynamodb delete-item \
--table-name <your_lock_table> \
--key '{
      "LockID": {"S":"<lock_id_discovered_during_previous_step>"}
  }' \
--profile=<your_profile>
```

---

_[View the full topic](https://discuss.hashicorp.com/t/s3-backend-state-lock-wont-release/21367)._
