Step-by-Step Guide to Creating an SQS Queue Using Terraform.

Step-by-Step Guide to Creating an SQS Queue Using Terraform.

What is AWS SQS?

Amazon SQS (Simple Queue Service) Dead Letter Queues (DLQs) are a feature that helps manage message processing failures in your messaging workflows. When messages in a standard SQS queue fail to be processed successfully after a certain number of attempts, they can be automatically sent to a DLQ.

DLQs can also be monitored for metrics like the number of messages and errors, which can help you maintain the health of your messaging system.

What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp, that lets you build, change, and version cloud and on-prem resources safely and efficiently in human-readable configuration files that you can version, reuse, and share.

Now, Create SQS in Terraform using VScode.

STEP 1: Navigate IAM and create Users.

  • Click on create user.
Screenshot 2025 01 13 095019

STEP 2: Enter the name and set password.

  • Click on next button.
Screenshot 2025 01 13 095147

STEP 3: Select attach policies directly.

  • Tick on Amazon SQS Fullaccess.
  • Click create user.
Screenshot 2025 01 13 095411
Screenshot 2025 01 13 095505

STEP 4: Click Return to user list.

Screenshot 2025 01 13 095633

STEP 5: Click on your username.

  • Create access key.
  • Select CLI.
Screenshot 2025 01 13 095712
Screenshot 2025 01 09 105316 1
Screenshot 2025 01 13 095758

STEP 6: You will get a secret key and Access Key.

  • If Download.csv file.
Screenshot 2025 01 13 095817

STEP 7: Go to VScode select your folder and create variable.tf file.

  • Enter the following commands and save it.
variable "access_key" {
    description = "Access key to AWS console"
}
variable "secret_key" {
    description = "Secret key to AWS console"
}
variable "region" {
    description = "AWS region"
}
Screenshot 2025 01 13 100603

STEP 8: Next, Create terraform.tf file.

  • Enter the command and save the file.
region = "us-east-1"
access_key = "<YOUR AWS CONSOLE ACCESS ID>"
secret_key = "<YOUR AWS CONSOLE SECRET KEY>"
Screenshot 2025 01 13 101046

STEP 9: Create main.tf file.

provider "aws" {
  region     = var.region
  access_key = var.access_key
  secret_key = var.secret_key
}
############ Creating FIFO Queue ############
resource "aws_sqs_queue" "queue" {
  name = "MyFirstQueue.fifo"
  fifo_queue = true
  content_based_deduplication = true
}
############ Creating Standard Queue ############
resource "aws_sqs_queue" "queue2" {
  name = "MyFirstQueue"
}
Screenshot 2025 01 13 101644

STEP 10: Create output.tf file.

output "sqs-queue-arn" {
    value = aws_sqs_queue.queue.arn
}
output "sqs-queue2-arn" {
    value = aws_sqs_queue.queue2.arn
}
Screenshot 2025 01 13 101802

STEP 11: Open the terminal Enter terraform init.

Screenshot 2025 01 13 102013

STEP 12: Next, Enter terraform plan command.

Screenshot 2025 01 13 102104

STEP 13: Enter terraform apply.

Screenshot 2025 01 13 102208
Screenshot 2025 01 13 102225

STEP 14: Go AWS SQS You can see two queues are created successfully.

Screenshot 2025 01 13 102310

STEP 15: If you delete the Queue use the terraform destroy command.

Screenshot 2025 01 13 102400

Conclusion.

By following these steps, you’ve successfully created an SQS Queue using Terraform, enabling you to manage your message queues in a scalable and automated manner. Terraform’s infrastructure-as-code approach makes it easier to maintain, version, and automate your AWS resources, ensuring a streamlined workflow.

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *