bug: SQS message does not trigger CloudWatch alarm
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
When I have a CloudWatch alarm for a message received in an SQS queue, it does not change state when I send a message in the queue
Expected Behavior
The alarm state would change to be in alarm after I send a message in the queue
How are you starting LocalStack?
With the localstack script
Steps To Reproduce
How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)
localstack start
Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
samlocal build
samlocal deploy --guided
aws --endpoint http://localhost:4566 sqs list-queues
aws --endpoint http://localhost:4566 sqs send-message --queue-url http://localhost:4566/000000000000/<queue name> --message-body hello
aws --endpoint http://localhost:4566 cloudwatch describe-alarms
Environment
- OS: macOS 12.5
- LocalStack: 1.1.0
Anything else?
CloudFormation template:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
Queue:
Type: AWS::SQS::Queue
Alarm:
Type: AWS::CloudWatch::Alarm
Properties:
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt Queue.QueueName
EvaluationPeriods: 1
MetricName: NumberOfMessagesReceived
Namespace: AWS/SQS
Period: 60
Statistic: Sum
Threshold: 0
Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our developer guide.
Hi @gdsgj,
thanks for reporting! I am flagging this as a feature request, because it is simply not yet implemented. SQS does currently not create any metrics in CloudWatch.
We will try to provide this functionality in an upcoming version. AWS states a list of metrics that should be available automatically, which we will take into consideration when implementing this feature.
Just a quick side-note @gdsgj :
In your example you are using the metric NumberOfMessagesReceived, which according to the docs is:
NumberOfMessagesReceived The number of messages returned by calls to the ReceiveMessage action.
As I understand, you want the ALARM state to be triggered once you send a message to the queue. It seems the metric to use should be:
NumberOfMessagesSent The number of messages added to a queue.
Could you confirm this?
Hi @gdsgj!
The latest image of localstack now includes SQS metrics. Please run docker pull localstack/localstack:latest.
I tested your sample with this version, and the CloudWatch Alarm will change to state ALARM when the NumberofMessagesReceived reaches the limit.
Please also consider my previous message, e.g. currently your alarm is configured to only trigger when you are receiving a message awslocal sqs receive-message --queue-url <url>.
If you want to be notified for messages send (awslocal sqs send-message ...) you will need to use NumberOfMessagesSent.
@steffyP: yes, my mistake. NumberOfMessagesReceived should only work if the receive action is called, which I did not include in steps to reproduce. NumberOfMessagesSent now works for me after running docker pull localstack/localstack:latest. Thank you very much!