How to fix Error creating SQS Queue: AWS.SimpleQueueService.QueueNameExists in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 30, 2025ยท 109 views

The QueueNameExists error occurs when Terraform attempts to create an SQS queue with a name that already exists in your AWS account and region. SQS queue names must be unique within each account and region, so this error indicates either a previous queue creation, a recent deletion that is still cached, or a naming conflict with another service.

Quick fix

Fixes QueueNameExists

aws sqs list-queues --queue-name-prefix my-queue-name --region us-east-1
  1. Verify the queue exists in your AWS account
  2. Import the existing queue into Terraform state
  3. Verify Terraform state matches your configuration
  4. Use a unique queue name with name_prefix
terraform โ€” error
aws sqs list-queues --queue-name-prefix my-queue-name --region us-east-1
Error creating SQS Queue: AWS.SimpleQueueService.QueueNameExists

What this error means

The QueueNameExists error means the SQS queue name you specified already exists in your AWS account within the same region. SQS queue names must be unique within each AWS account and region combination - you cannot have two queues with the same name in the same account and region. This constraint is enforced by the AWS SQS service and Terraform will fail resource creation when this condition is detected.

Typical symptoms

  • Terraform apply fails when creating aws_sqs_queue resource
  • Error message includes "QueueNameExists" or "queue name exists"
  • apply fails with AWS.SimpleQueueService.QueueNameExists error
  • Queue was just deleted but immediately recreating fails
  • Another Terraform workspace or manual creation created a queue with the same name
  • Queue creation worked previously but now fails with this error
  • Terraform state file is out of sync with actual AWS queues

Common causes

  1. The queue was created in a previous Terraform run and still exists in AWS
  2. The queue was created manually in AWS Console or via AWS CLI outside Terraform
  3. Terraform state file does not reference the existing queue, creating a mismatch
  4. Another team member or service created a queue with the same name
  5. A failed Terraform run left the queue partially created
  6. The queue was recently deleted and is still cached by AWS (60-second grace period)
  7. Multiple Terraform runs or automation scripts are attempting to create the same queue simultaneously

How to fix "Error creating SQS Queue: AWS.SimpleQueueService.QueueNameExists"

1Verify the queue exists in your AWS account

Check if the queue actually exists using the AWS CLI:

bash
aws sqs list-queues --queue-name-prefix my-queue-name --region us-east-1

Replace "my-queue-name" and "us-east-1" with your actual queue name and region. If the queue URL appears in the output, the queue exists.

2Import the existing queue into Terraform state

If you own the queue and want Terraform to manage it, import it:

bash
aws sqs get-queue-url --queue-name my-queue-name --region us-east-1

Copy the QueueUrl from the output, then:

bash
terraform import aws_sqs_queue.my_queue <queue-url>

Replace "my_queue" with your resource name and use the actual queue URL.

3Verify Terraform state matches your configuration

Check if the queue is already tracked in your Terraform state:

bash
terraform state list | grep sqs_queue
terraform state show aws_sqs_queue.my_queue

If the resource exists in state but references the wrong queue, remove and re-import it:

bash
terraform state rm aws_sqs_queue.my_queue
terraform import aws_sqs_queue.my_queue <queue-url>
4Use a unique queue name with name_prefix

Let Terraform generate a unique suffix for the queue name:

hcl
resource "aws_sqs_queue" "my_queue" {
  name_prefix = "my-queue-"
}

Terraform will create a queue like "my-queue-a1b2c3d4e5f6abcd". This avoids naming conflicts.

5Add a unique identifier to the queue name

Make the queue name unique by including your AWS account ID or environment:

hcl
data "aws_caller_identity" "current" {}

resource "aws_sqs_queue" "my_queue" {
  name = "my-queue-${data.aws_caller_identity.current.account_id}"
}

Or include the environment:

hcl
resource "aws_sqs_queue" "my_queue" {
  name = "my-queue-${var.environment}"
}
6Delete the queue if you want to recreate it fresh

If you no longer need the existing queue, delete it using the AWS CLI:

bash
aws sqs delete-queue --queue-url <queue-url> --region us-east-1

Then run Terraform apply:

bash
terraform apply

Note: AWS has a 60-second grace period after deletion before you can reuse the queue name.

7Wait for the 60-second grace period if recently deleted

If you just deleted a queue and are trying to recreate it with the same name, AWS requires a 60-second wait:

bash
# Wait 60 seconds
sleep 60

# Then run Terraform apply
terraform apply

This grace period prevents accidental recreation issues and ensures consistency across AWS systems.

Advanced notes

## SQS Queue Naming Rules
- Names must be 1-80 characters long
- Can contain lowercase letters, numbers, hyphens, and underscores
- FIFO queues must end with .fifo
- Names are case-sensitive

## 60-Second Grace Period
After deleting an SQS queue, its name is unavailable for 60 seconds. Attempting to recreate a queue with the same name within this window will fail with QueueNameExists. This is an AWS safety mechanism.

## Queue Deletion vs Queue Purge
- delete-queue: Removes the entire queue (frees up the name after 60s)
- purge-queue: Removes all messages but keeps the queue (name stays reserved)

If you only want to clear messages, use purge instead of delete.

## Regional Isolation
Queue names are unique per region per account. You can have a queue named "my-queue" in us-east-1 and a different queue with the same name in eu-west-1.

## Terraform Lifecycle Rules
For development/testing scenarios where you need to replace a queue:

hcl
resource "aws_sqs_queue" "my_queue" {
  name = "my-queue"

  lifecycle {
    create_before_destroy = true
  }
}

This creates the new queue before destroying the old one, but you'll still need a unique name.

Frequently asked questions

What does "QueueNameExists" mean?
The QueueNameExists error means the SQS queue name you specified already exists in your AWS account within the same region. SQS queue names must be unique within each AWS account and region combination - you cannot have two queues with the same name in the same account and region. This constraint is enforced by the AWS SQS service and Terraform will fail resource creation when this condition is detected.
How do I fix "QueueNameExists"?
The QueueNameExists error occurs when Terraform attempts to create an SQS queue with a name that already exists in your AWS account and region. SQS queue names must be unique within each account and region, so this error indicates either a previous queue creation, a recent deletion that is still cached, or a naming conflict with another service.
What causes "QueueNameExists"?
The queue was created in a previous Terraform run and still exists in AWS The queue was created manually in AWS Console or via AWS CLI outside Terraform Terraform state file does not reference the existing queue, creating a mismatch
Is the "QueueNameExists" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading