DC_Valluru
DC_Valluru

Reputation: 113

Creating alarms for existing SQS queues using script

I am trying to create alarms based on existing SQS queue metrics in my AWS account using cloud formation. I have more than 25 SQS queues and don't want to repeat the code where I mention the SQS queues one by one. Is there an effective method (shorter code) to create the alarms using programming?

Here is the YAML code for the CloudFormation template. In this, I have mentioned one of the queues from my existing queues.

Parameters:
  SQSAlarm:
    Type: String
    Description: Alarm for existing SQS Queues
    Default: Queue1
  SQSAlarm:
    Type: String
    Description: Alarm for existing SQS Queues
    Default: Queue3

Resources:
  MyAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName:
        !Ref SQSAlarm
      MetricName: "QueueName"
      Namespace: AWS/SQS
      Statistic: Average
      Period: 60
      EvaluationPeriods: 1
      Threshold: 60
      ComparisonOperator: GreaterThanThreshold
      MetricName: ApproximateAgeOfOldestMessage
      AlarmActions:
        - arn:aws:sns:us-east-1:589557565942:SQS-Oldest-Message
      Dimensions:
        - Name: QueueName
          Value: !Ref SQSAlarm

Upvotes: 1

Views: 1258

Answers (1)

Marcin
Marcin

Reputation: 238051

There are no loops in CloudFormation (CFN). The only solutions for you would be as follows:

  • create CFN macro, to auto generate the queues definitions automatically.
  • create a custom resource to "manually" create the queues using a lambda function and AWS SDK.
  • use nested stack, which still needs to be repeated, but maybe it will be shorter.
  • don't use CFN. There are other, much more power IaC tools, such as Terraform, which have loops and reach portfolio of programming techniques which would make it easy to auto-generate those queues.

Upvotes: 1

Related Questions