Menu

Sponsored By: Password Angel - Share passwords, API keys, credentials and more with secure, single-use links.

SQS Queue: How many messages have been received?

Using the CloudWatch API and the AWS CLI to get the number of messages received (Metric = NumberOfMessagesReceived) by an SQS queue for a week.

Syntax

aws cloudwatch get-metric-statistics \
  --namespace AWS/SQS \
  --start-time 2022-09-20T00:00:00Z \
  --end-time 2022-09-28T00:00:00Z \
  --period 86400 \
  --metric-name NumberOfMessagesReceived \
  --dimensions Name=QueueName,Value=[INSERT QUEUE NAME HERE] \
  --statistics Sum \
  --output json 

Result

The output should resemble something like

{
    "Label": "NumberOfMessagesReceived",
    "Datapoints": [
        {
            "Timestamp": "2022-09-24T00:00:00+00:00",
            "Sum": 48.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2022-09-27T00:00:00+00:00",
            "Sum": 144.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2022-09-23T00:00:00+00:00",
            "Sum": 51.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2022-09-26T00:00:00+00:00",
            "Sum": 2094.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2022-09-22T00:00:00+00:00",
            "Sum": 0.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2022-09-25T00:00:00+00:00",
            "Sum": 334.0,
            "Unit": "Count"
        }
    ]
}

If you receive something like

{
    "Label": "NumberOfMessagesReceived",
    "Datapoints": []
}

Then you likely have got the --metric-name value incorrect, or you are missing the argument completely. Originally omitted the --dimensions argument hoping to get the data for all queues but ended up with the empty response above instead.

Originally published at https://chrisshennan.com/blog/aws-sqs-queue-how-many-messages-have-been-received

Subscribe to my newsletter...

... and get the ramblings of a wannabe #indiehacker straight in your inbox once a month.

Ramblings will cover a variety of topics including Web Development, DevOps, Startups, Bootstrapping, #buildinpublic, SEO, opinion and personal experience.

Is it for you? - Why not check out my past issues.

I won't send you spam and you can unsubscribe at any time.