[Yandex Cloud documentation](../../index.md) > [Yandex Message Queue](../index.md) > [Step-by-step guides](index.md) > Creating a new message queue

# Creating a new message queue

Message queues in Message Queue enable [messaging](../concepts/message.md) between components of distributed applications. Messages can be sent to queues using the [API](../api-ref/index.md) or other supported [tools](../instruments/index.md).

To create a new message queue:

{% list tabs group=instructions %}

- Management console {#console}
  
  1. In the [management console](https://console.yandex.cloud), select the folder to create your queue in.
  1. Navigate to **Message Queue**.
  1. Click **Create queue**.
  1. Under **Basic parameters**, fill in the following fields:
      * **Name**: Enter a name for the queue.
  
        The name may contain lowercase Latin letters, numbers, hyphens, and underscores. The FIFO queue name must end with the `.fifo` suffix. The name may not be longer than 80 characters.
  
      * **Type**: Select the `Standard` or `FIFO` queue type.
      * **Standard visibility timeout**: Specify the standard visibility timeout to be applied to enqueued messages after they are read by a consumer.
      * **Message retention**: Set the maximum period for retaining messages in the queue.
      * **Maximum message size**: Specify the maximum message size.
      * **Delivery delay**: Specify the amount of time during which a new message cannot be picked from the queue.
      * **Timeout for receiving messages**: Specify the message receipt timeout.
  1. To redirect undelivered messages to the [dead letter queue (DLQ)](../concepts/dlq.md), do the following under **Configure undelivered message queues**:
      * Enable **Redirect undelivered messages**.
      * Specify **Undelivered messages queue**.
      * Set the **Maximum number of read attempts**.
  1. Click **Create**.

- AWS CLI {#cli}

  1. [Install and configure](configuring-aws-cli.md) the AWS CLI.

  1. Run the following command in the terminal:
  
     ```bash
     aws sqs create-queue \
       --queue-name <queue_name> \
       --endpoint <endpoint>
     ```

     Where:

     * `--queue-name`: Name of the new queue, e.g., `sample-queue`.
     * `--endpoint`: Endpoint in the `https://message-queue.api.cloud.yandex.net/` value.
      
     Result:

     ```json
     {
         "QueueUrl": "https://message-queue.api.cloud.yandex.net/aoeaql9r10cd********/000000000000********/sample-queue"
     }
     ```

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the relevant documentation on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).
  
    If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
    
    
    To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.
  
    To create a message queue: 
      
    1. In the configuration file, describe the parameters of the queue to create:
              
       Sample configuration file for a standard queue:
  
       ```hcl
       provider "yandex" {
         folder_id = "<folder_ID>"
         zone      = "ru-central1-a"
       }
  
       resource "yandex_message_queue" "example_queue" {
         name                        = "mq-terraform-example"
         visibility_timeout_seconds  = 600
         receive_wait_time_seconds   = 20
         message_retention_seconds   = 1209600
         access_key                  = "<static_access_key_ID>"
         secret_key                  = "<secret_part_of_static_access_key>"
       }
       ```
  
       Sample configuration file for a FIFO queue:
  
       ```hcl
       provider "yandex" {
         folder_id = "<folder_ID>"
         zone      = "ru-central1-a"
       }
  
       resource "yandex_message_queue" "example-fifo-queue" {
         name                        = "mq-terraform-example.fifo"
         visibility_timeout_seconds  = 600
         receive_wait_time_seconds   = 20
         message_retention_seconds   = 1209600
         fifo_queue                  = true
         access_key                  = "<static_access_key_ID>"
         secret_key                  = "<secret_part_of_static_access_key>"
       }
       ```
  
       Example of a configuration file for a queue with a redirect policy for moving undelivered messages to a DLQ named `mq_terraform_deadletter_example`:
  
       ```hcl
       provider "yandex" {
         folder_id = "<folder_ID>"
         zone      = "ru-central1-a"
       }
  
       resource "yandex_message_queue" "example_fifo_queue" {
         name                        = "mq-terraform-example"
         visibility_timeout_seconds  = 600
         receive_wait_time_seconds   = 20
         message_retention_seconds   = 1209600
         redrive_policy              = jsonencode({
           deadLetterTargetArn = yandex_message_queue.example_deadletter_queue.arn
           maxReceiveCount     = 3
         })
         access_key                  = "<static_access_key_ID>"
         secret_key                  = "<secret_part_of_static_access_key>"
       }
  
       resource "yandex_message_queue" "example_deadletter_queue" {
         name                        = "mq_terraform_deadletter_example"
         access_key                  = "<static_access_key_ID>"
         secret_key                  = "<secret_part_of_static_access_key>"
       }
       ```
  
       Where:
  
       * `name`: Queue name.
       * `visibility_timeout_seconds`: [Visibility timeout](../concepts/visibility-timeout.md).
       * `receive_wait_time_seconds`: Waiting time for messages to enter the queue if [Long Polling](../concepts/long-polling.md) is used. The valid values are from 0 to 20 seconds. The default value is 0 seconds.
       * `message_retention_seconds`: Message retention time in the queue, in seconds.
       * `redrive_policy`: Redirect policy for moving messages to a [dead-letter queue](../concepts/dlq.md).
         * `deadLetterTargetArn`: ARN of the DLQ messages will be redirected to.
         * `maxReceiveCount`: Number of attempts to read a message from the queue before redirecting it to the DLQ.
       * `fifo_queue`: Indicates that a [FIFO queue](../concepts/queue.md#fifo-queues) is created.
       * `content_based_deduplication`: Enables [content-based deduplication](../concepts/deduplication.md#content-based-deduplication) in FIFO queues.
       * `access_key`: ID of the service account's static access key for the queue. If it is not specified in the queue configuration, the ID from the provider configuration is used.
       * `secret_key`: Secret part of the static access key. If no secret key is set in the queue configuration, the key from the provider configuration is used.
  
       For more information about the resources you can create with Terraform, see [this provider guide](../../terraform/index.md).
       
    1. Make sure the configuration files are correct.
       
       1. In the terminal, navigate to the directory where you created your configuration file.
       1. Run a check using this command:
          ```
          terraform plan
          ```
       If the configuration is correct, the terminal will display a list of the resources and their settings. Otherwise, Terraform will show any detected errors. 
          
    1. Deploy the cloud resources.
  
       1. If the configuration is correct, run this command:
          ```
          terraform apply
          ```
       1. Confirm creating the resources.
       
       This will create all the resources you need in the specified folder. You can check the new resources and their settings in the [management console](https://console.yandex.cloud). To delete the resources you created, run the `terraform destroy` command.

{% endlist %}


When the limit on the maximum number of queues is reached, the `Cannot create queue: Too many queues` error occurs. To increase the limit, contact [technical support](https://center.yandex.cloud/support).