Skip to content
Latchkey

aws sqs CLI: Queues, Send and Receive

aws sqs create-queue, send-message, and receive-message manage an SQS queue from the shell, and --endpoint-url points them at LocalStack for offline CI.

For queue-backed integration tests you rarely hit real SQS; you run LocalStack or ElasticMQ and aim the same aws sqs commands at it with --endpoint-url. The command shapes are identical.

What it does

The aws sqs subcommands wrap the SQS API. create-queue returns a QueueUrl; send-message posts a body to that URL; receive-message polls for messages (with optional long polling). Against a local emulator you add --endpoint-url to redirect from real AWS.

Common usage

Terminal
# create a queue (against LocalStack)
aws --endpoint-url=http://localhost:4566 sqs create-queue \
  --queue-name orders
# send a message
aws --endpoint-url=http://localhost:4566 sqs send-message \
  --queue-url http://localhost:4566/000000000000/orders \
  --message-body '{"id":1}'
# receive with long polling
aws --endpoint-url=http://localhost:4566 sqs receive-message \
  --queue-url http://localhost:4566/000000000000/orders \
  --wait-time-seconds 5 --max-number-of-messages 1

Options

FlagWhat it does
create-queue --queue-name <n>Create a queue, returns QueueUrl
send-message --queue-url <u> --message-body <b>Send a message
receive-message --queue-url <u>Poll for messages
--wait-time-seconds <n>Long-poll wait (0-20)
--max-number-of-messages <n>Up to 10 messages per receive
--endpoint-url <url>Target LocalStack/ElasticMQ instead of AWS

In CI

Use --wait-time-seconds for long polling so a receive does not return empty on the first try before the message lands. Against LocalStack, set dummy AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (any value) and a region, or the CLI refuses to sign the request.

Common errors in CI

"Could not connect to the endpoint URL" means the emulator is not up on that --endpoint-url yet; wait for the service. "Unable to locate credentials" means AWS_ACCESS_KEY_ID/SECRET are unset even for LocalStack; export dummy values. "AWS.SimpleQueueService.NonExistentQueue" means the queue-url is wrong or the queue was never created. A receive returning nothing is normal when the queue is empty; use long polling.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →