getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
915 stars 114 forks source link

New Construct proposal: SNS notification #83

Open carvajalluis opened 3 years ago

carvajalluis commented 3 years ago

there is a large chance that at some point you need an outgoing notification topic with its permissions and policy to provide event driven architecture intercommunication, to notify end users , to notify it , etc. So that you can reference it from lambda code.

mnapoli commented 3 years ago

Hi, thanks for opening this issue!

Could you explain in a bit more detail what you have in mind? Would it be a construct to handle SNS notifications, or to send them?

If you have a proposal of YAML syntax feel free.

carvajalluis commented 3 years ago

Hello @mnapoli , definitely send is my current intent. I'm a bit rough yet on serverless and it might not be complete or production ready but this is what I have been creating.

resources:
  Resources:
    AlarmTopic:
      Type: AWS::SNS::Topic
      Properties:
        DisplayName: "User alerts"
        TopicName: user-alert-${self:provider.stage}
        Subscription:
          - Endpoint: user@mail.com
            Protocol: email
    AlarmTopicPolicy:
      Type: AWS::SNS::TopicPolicy
      DependsOn:
        - AlarmTopic
      Properties:
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
            - Sid: AllowServerlessFrameworkEnterpriseToPublish
              Effect: Allow
              Resource: !Ref AlarmTopic
              Principal:
                Service: lambda.amazonaws.com
              Action: "sns:Publish"
        Topics:
          - Ref: AlarmTopic
  Outputs:
    AlarmSnsTopicArn:
      Description: ARN for the SNS Alarm Topic
      Value: !Ref AlarmTopic

some thing along those lines where I can create a construct and give it publish access to any particular construct worker. i could have some misconception yet so please correct me if I'm wrong.

mnapoli commented 3 years ago

OK I see, thanks!

The end goal here is to add email alarms, right? I'm wondering if this isn't something we should solve directly (the high level problem). I'd be interested to know how you use the alarm? (what triggers it)