Menu
Amazon Simple Queue Service
Developer Guide

Tutorial: Creating an Amazon SQS Queue

The first and most common Amazon SQS task is creating queues. The following example demonstrates how to create and configure a queue.

AWS Management Console

  1. Sign in to the AWS Management Console and open the Amazon SQS console at https://console.aws.amazon.com/sqs/.

  2. Choose Create New Queue.

  3. On the Create New Queue page, ensure that you're in the correct region and then type the Queue Name.

    Note

    The name of a FIFO queue must end with the .fifo suffix. FIFO queues are available in the US West (Oregon) and US East (Ohio) regions.

  4. Standard is selected by default. Choose FIFO.

  5. Create your queue.

    • To create your queue with the default parameters, choose Quick-Create Queue.

    • To configure your queue's parameters, choose Configure Queue. When you finish configuring the parameters, choose Create Queue.

      The following example shows the Content-Based Deduplication parameter specific to FIFO queues.

    Your new queue is created and selected in the queue list. When you create a queue, it can take a short time for the queue to propagate throughout Amazon SQS.

    The Queue Type column helps you distinguish standard queues from FIFO queues at a glance. For a FIFO queue, the Content-Based Deduplication column displays whether you have enabled exactly-once processing.

    Your queue's URL and ARN are displayed on the Details tab.

Java

Before you begin working with the example code, specify your AWS credentials. For more information, see Set Up AWS Credentials for Development in the AWS SDK for Java Developer Guide.

To create a standard queue

  1. Copy the example program.

    The following section of the code creates the MyQueue queue:

    Copy
    // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
  2. Compile and run the example.

    The queue is created.

To create a FIFO queue

  1. Copy the example program.

    The following section of the code creates the MyFifoQueue.fifo queue:

    Copy
    // Create a FIFO queue System.out.println("Creating a new Amazon SQS FIFO queue called MyFifoQueue.fifo.\n"); Map<String, String> attributes = new HashMap<String, String>(); // A FIFO queue must have the FifoQueue attribute set to True attributes.put("FifoQueue", "true"); // Generate a MessageDeduplicationId based on the content, if the user doesn't provide a MessageDeduplicationId attributes.put("ContentBasedDeduplication", "true"); // The FIFO queue name must end with the .fifo suffix CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyFifoQueue.fifo").withAttributes(attributes); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
  2. Compile and run the example.

    The queue is created.

AWS CloudFormation

You can use the AWS CloudFormation console and a JSON (or YAML) template to create an Amazon SQS queue. For more information, see Working with AWS CloudFormation Templates and the AWS::SQS::Queue Resource in the AWS CloudFormation User Guide.

  1. Copy the following JSON code to a file named MyQueue.json. To create a standard queue, omit the FifoQueue and ContentBasedDeduplication properties. For more information on content-based deduplication, see Exactly-Once Processing.

    Note

    The name of a FIFO queue must end with the .fifo suffix. FIFO queues are available in the US West (Oregon) and US East (Ohio) regions.

    Copy
    { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MyQueue": { "Properties": { "QueueName": "MyQueue.fifo", "FifoQueue": true, "ContentBasedDeduplication": true }, "Type": "AWS::SQS::Queue" } }, "Outputs": { "QueueName": { "Description": "The name of the queue", "Value": { "Fn::GetAtt": [ "MyQueue", "QueueName" ] } }, "QueueURL": { "Description": "The URL of the queue", "Value": { "Ref": "MyQueue" } }, "QueueARN": { "Description": "The ARN of the queue", "Value": { "Fn::GetAtt": [ "MyQueue", "Arn" ] } } } }
  2. Sign in to the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation, and then choose Create Stack.

  3. On the Select Template page, choose Upload a template to Amazon S3, choose your MyQueue.json file, and then choose Next.

  4. On the Specify Details page, type MyQueue for Stack Name, and then choose Next.

  5. On the Options page, choose Next.

  6. On the Review page, choose Create.

    AWS CloudFormation begins to create the MyQueue stack and displays the CREATE_IN_PROGRESS status. When the process is complete, AWS CloudFormation displays the CREATE_COMPLETE status.

  7. (Optional) To display the name, URL, and ARN of the queue, choose the name of the stack and then on the next page expand the Outputs section.