# Change the visibility of a message

Give a consumer more time for a received message, or release it to the queue at once.

Replace _my-queue_ with the name of your queue and _receipt-handle_ with the receipt handle of the
message's latest receive. The new timeout counts from now, 0 to 43,200 seconds (12 hours); 0 makes
the message receivable again at once.

## Prerequisites

- Permission for `queue:ChangeMessageVisibility` on the queue. In the console you also need
  `queue:ReceiveMessage` to poll for the message; without `queue:ChangeMessageVisibility`,
  **Release** is unavailable.
- In the console, also `queue:GetQueueAttributes` to open the queue's page (without it the page is
  not found).
- The message is in flight under that receipt handle: no one has received it since, and its
  visibility timeout has not ended.

## Change the visibility

**Console**
The console only releases a message:

1. Open the queue, then choose **Send and receive**.
2. Under **Receive messages**, choose **Poll for messages**.
3. On the message, choose **Release**.

The message leaves the list and can be received again at once.

**CLI**
```sh
dcloud queue messages change-visibility my-queue --receipt-handle receipt-handle --visibility-timeout-seconds 300
```

**API**
```http
POST /queue/api/queues/my-queue/messages/visibility
{ "receiptHandle": "…", "visibilityTimeoutSeconds": 300 }
```

Up to 10 messages in one request, each with an `id` of your choosing:

```http
POST /queue/api/queues/my-queue/messages/visibility-batch
{ "entries": [ { "id": "a", "receiptHandle": "…", "visibilityTimeoutSeconds": 0 } ] }
```

The batch answers `200` with `successful` and `failed` per `id`; a failed entry does not fail the
others.

**Terraform:** not available. Changing a message's visibility is an action, not configuration.

## Result

The message stays hidden for the new timeout, counted from now; with 0 it can be received again at
once. Its receipt handle still deletes it until it is received again. A further change with the same
handle works only while the message is still hidden: once its timeout has ended, or after a change
to 0, the change is refused with `MessageNotInflight`.

## When the change is refused

- `400` with code `MessageNotInflight`: "The message is not in flight under this receipt — it was
  deleted, became visible again, or was received by someone else."
- `400` "That is not a receipt handle."

## Related

- [Receive and delete messages](receive-and-delete-messages.md)
- [Message delivery](message-delivery.md)
