Amazon SQS
Read Amazon SQS queue attributes
Use the AWS CLI to inspect a queue’s settings or approximate message counts. Use the Go SDK when an application needs the same named attributes.
Documentation reviewed · 2 methods with sources
Ways to do it
CLI
aws sqs get-queue-attributes
Pass a queue URL and list the attributes you want, such as VisibilityTimeout and ApproximateNumberOfMessages.
Read source: AWS CLI get-queue-attributes- Requirements
- AWS CLI credentials with sqs:GetQueueAttributes, the queue URL, and its Region.
- Limitations
- The message count is approximate and can take at least a minute to settle after producers stop sending.
Example shell
aws sqs get-queue-attributes --queue-url "$QUEUE_URL" --attribute-names VisibilityTimeout ApproximateNumberOfMessagesSDK
sqs.Client.GetQueueAttributes
Set QueueUrl and the requested AttributeNames on GetQueueAttributesInput. Read the response’s string-valued Attributes map.
Read source: AWS SDK for Go v2 GetQueueAttributes- Requirements
- An AWS SDK for Go v2 SQS client configured with credentials, the queue’s Region, and sqs:GetQueueAttributes permission.
- Limitations
- The SDK returns an empty attribute result when you omit AttributeNames. Request specific names or use All.