How can I get a ref QueueName ? ref(:mydeadletterqueue) is returning the ARN. I tried to extract the Name from the ARN like this ref(:mydeadletterqueue).rpartition(’:’).last, but it’s not working. Is there a way to achieve this?
I’ve been able to get it doing this: MyDeadLetterQueue.lookup(:mydeadletterqueue).rpartition(':').last
class MyDeadLetterQueue < Jets::Stack
sqs_queue(:mydeadletterqueue, visibility_timeout: 180)
end
class AlertSns < Jets::Stack
sns_topic(:notification_alert, display_name: "AWS - Alert")
sns_subscription(:subscription_sns, topic_arn: ref(:notification_alert), protocol: "email", endpoint: Jets.config.email_for_alerts)
end
class AlarmSns < Jets::Stack
depends_on :alert_sns
depends_on :mydeadletterqueue
# Jets.aws.account must be set for MyDeadLetterQueue.lookup() to work
begin
account = Jets.aws.account
rescue
account = nil
end
if account.present?
cloudwatch_alarm(:dlq_alarm,
alarm_actions: [ref(:notification_alert)],
alarm_description: "DLQ Alarm",
alarm_name: "DLQ Alarm",
comparison_operator: "GreaterThanOrEqualToThreshold",
datapoints_to_alarm: 1,
dimensions: [{name: "QueueName", value: MyDeadLetterQueue.lookup(:mydeadletterqueue).rpartition(':').last}],
evaluation_periods: 1,
metric_name: "NumberOfMessagesReceived",
namespace: "AWS/SQS",
period: 60,
statistic: "Sum",
threshold: 1,
treat_missing_data: "notBreaching"
)
end
end
There’s probably a better way to do this because it’s crashing when runned via the Jets Console because it needs the AWS credentials to get the ARN. That’s the reason why there’s a check on Jets.aws.account.