1. How to exclude NaN alerts from SQS monitoring?

    Python

    Currently, there's no native way to exclude NaN (not a number) alerts specifically from Pulumi's SQS monitoring. However, you can control the alerts by setting up proper alert conditions.

    You can use the aws-native.cloudwatch.Alarm or aws.cloudwatch.MetricAlarm resource to monitor an SQS queue based on various metrics such as ApproximateNumberOfMessagesVisible, ApproximateAgeOfOldestMessage, etc. By carefully setting the thresholds of these metrics in the alarm settings, you can avoid receiving unnecessary alerts.

    Here's a sample program that sets up an alarm on the ApproximateNumberOfMessagesVisible SQS metric:

    import pulumi import pulumi_aws as aws # Create an SQS queue queue = aws.sqs.Queue('myQueue') # Get the ApproximateNumberOfMessagesVisible metric for the SQS queue metric = aws.cloudwatch.Metric( namespace='AWS/SQS', name='ApproximateNumberOfMessagesVisible', dimensions={ 'QueueName': queue.name } ) # Setup a CloudWatch alarm on ApproximateNumberOfMessagesVisible metric alarm = aws.cloudwatch.MetricAlarm( 'myAlarm', comparison_operator="GreaterThanOrEqualToThreshold", evaluation_periods=2, metric_name=metric.name, namespace=metric.namespace, period=120, statistic="Average", alarm_description="This metric checks number of visible messages", alarm_actions=[], # Specify the actions to perform when alarm state is triggered dimensions=metric.dimensions, threshold=200, # Define a threshold for messages in the Queue ) # Export the URL of the SQS queue pulumi.export("queue_url", queue.id)

    This alarm is designed to get triggered if the number of messages in the queue exceeds 200 for a period of 120 seconds. This can prevent alerts for momentary surge of messages in the queue. Adjust the threshold and period based on the behavior of your application to fine tune the alerts.

    Refer to MetricAlarm documentation for more details on how to configure the alarm.