Cloudformation: connect lambda to an exisitng SNS topic ?

0

Hello,

With cloudformation, is it possible to connecting a lambda to an existing SNS topic ?

I've tried with "AWS::Events::Rule" with this code (yaml)

      LambdaInvokeEventRule:
        Type: AWS::Events::Rule
        Properties:
          Name: "MyLambda"
          RoleArn: !GetAtt MyLambdaRole.Arn
          EventPattern: 
            source: 
              - "aws.sns"
            resources:
              - "arn:aws:sns:eu-west-1:643462973525:mytopic"
          Targets:
              - Arn: !GetAtt MyLambda.Arn
                Id: "MyLambda"

But the validation fails with this message "Invalid template resource property" for this block

Thanks !!

gefragt vor 5 Jahren2216 Aufrufe
2 Antworten
0

Hi,
Just to clarify. When the sns Topic gets a message, you want it to invoke a Lambda function to process the message that was sent to the SNS topic. If yes, then you want to create your Cloudformation template to look something like the following:

 
Parameters:
  MyLambdaArn:
    Type: String
    Default: arn:aws:lambda:us-east-1:XXXXXXXXXX:function:MyLambda
    Description: Enter the Lambda ARN
    
Resources:
  lambdaTopic:
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: Topic that invokes the Lambda function
      Subscription:
        - Endpoint: !Ref MyLambdaArn
          Protocol: lambda

  lambdaPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !Ref MyLambdaArn
      Principal: sns.amazonaws.com
      SourceArn: arn:aws:sns:eu-west-1:643462973525:mytopic

Hope that helps.
-randy

Edited by: rtakeshi on Aug 7, 2019 10:05 AM

beantwortet vor 5 Jahren
0

OK, I had use this solution first.

The SNS topic has created by an other teams but it make sens that the Lambda creation section must be present in their cloudformation file.

Very thanks !

beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen