Skip to content

Instantly share code, notes, and snippets.

@j3tm0t0
Last active May 9, 2016 22:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j3tm0t0/81f06fe55e30d8466100 to your computer and use it in GitHub Desktop.
Save j3tm0t0/81f06fe55e30d8466100 to your computer and use it in GitHub Desktop.
periodic sns alarm by itself (for cron-like lambda execution)
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"period": {
"Default": 3300,
"Description": "SQS message lifetime. SNS events will be kicked every (300 + this value) seconds",
"Type": "Number"
}
},
"Resources": {
"sqs": {
"Type": "AWS::SQS::Queue",
"Properties": {
"MessageRetentionPeriod": {
"Ref": "period"
}
}
},
"sqsPolicy": {
"Type": "AWS::SQS::QueuePolicy",
"Properties": {
"Queues": [
{
"Ref": "sqs"
}
],
"PolicyDocument": {
"Id": "QueuePolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow-User-SendMessage",
"Effect": "Allow",
"Principal": "*",
"Action": [
"sqs:SendMessage"
],
"Resource": "*",
"Condition": {
"ArnEquals": {
"aws:SourceArn": {
"Ref": "sns"
}
}
}
}
]
}
}
},
"sns": {
"Type": "AWS::SNS::Topic",
"Properties": {
"Subscription": [
{
"Endpoint": {
"Fn::GetAtt": [
"sqs",
"Arn"
]
},
"Protocol": "sqs"
}
]
}
},
"alarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": "Alarm if no message in queue",
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Dimensions": [
{
"Name": "QueueName",
"Value": {
"Fn::GetAtt": [
"sqs",
"QueueName"
]
}
}
],
"Statistic": "Minimum",
"Period": "300",
"EvaluationPeriods": "1",
"Threshold": "0",
"ComparisonOperator": "LessThanOrEqualToThreshold",
"AlarmActions": [
{
"Ref": "sns"
}
],
"InsufficientDataActions": [
{
"Ref": "sns"
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment