serverless-plugin-aws-alerts icon indicating copy to clipboard operation
serverless-plugin-aws-alerts copied to clipboard

`Ref` a topic created in Resources

Open julienmachon opened this issue 6 years ago • 2 comments

This is a Feature Proposal

Description

Being able to reference a topic created by a CloudFormation template.

custom: 
  alerts:
    topics:
      ok:
        Ref: SNSTopic
      alarm:
        Ref: SNSTopic
      insufficientData:
        Ref: SNSTopic

resources:
  Resources:
    SNSTopic:
      Type: AWS::SNS::Topic
      Properties:
        DisplayName: ${self:service}-${opt:stage}
        Subscription:
          - Endpoint: https://api.opsgenie.com/v1/json/cloudwatch?apiKey=${ssm:/opsgenie/${opt:stage}/api_key}
            Protocol: HTTPS

In some cases, I just want to Ref my SNS topic as I might also be using that ARN somewhere else in my stack.

I have a PR, ready and tested.

Thanks Julien

julienmachon avatar Aug 07 '18 08:08 julienmachon

That said, I have found a workaround my issue by naming my Topic and manually building the ARN with the help of the serverless-pseudo-parameters plugin.

It's not very elegant, but it works...

plugins:
  - serverless-plugin-aws-alerts
  - serverless-pseudo-parameters

custom: 
  alerts:
    topics:
      ok: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:service}-${self:provider.stage}
      alarm: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:service}-${self:provider.stage}
      insufficientData: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:service}-${self:provider.stage}

resources:
  Resources:
    SNSTopic:
      Type: AWS::SNS::Topic
      Properties:
        DisplayName: ${self:service}-${self:provider.stage}
        TopicName:  ${self:service}-${self:provider.stage}
        Subscription:
          - Endpoint: https://api.opsgenie.com/v1/json/cloudwatch?apiKey=${ssm:/opsgenie/${opt:stage}/api_key}
            Protocol: HTTPS

julienmachon avatar Aug 09 '18 12:08 julienmachon

Two years later - what can we do to get this in? This is a pretty important feature to have.

et304383 avatar Sep 30 '20 12:09 et304383