简体   繁体   中英

Trigger lambda from SNS Topic in cloudformation

I can't find a way to make this SNS topic trigger my lambda in this cloudformation script, the stack gets created successfuly, the lambda is added as a subscriber to the SNS Topic, but i can't figure out ho to add theh SNS Topic as a trigger to the lambda from within the script, when an alarm sends an event into the topic, the lambda doesn't get triggered at all

  Resources:
    TriggerTopic:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: TRIGGER_TOPIC
        Subscription:
          - Protocol: lambda
            Endpoint: !GetAtt TriggerLambda.Arn
  
    TriggerLambda:
      Type: AWS::Lambda::Function
      Properties:
        Code:
          S3Bucket: !Ref LambdaS3Bucket
          S3Key: !Ref LambdaS3Key
        Handler: !Ref LambdaHandler
        Runtime: java8
        Description: Trigger lambda
        MemorySize: 512
        Timeout: 30
        Role: !GetAtt LambdaRole.Arn
  
    LambdaRole:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Version: 2012-10-17
          Statement:
            - Action:
                - sts:AssumeRole
              Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
        ManagedPolicyArns:
          - 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
          - 'arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole'
          - 'arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess'
          - 'arn:aws:iam::aws:policy/AWSLambdaReadOnlyAccess'
          - 'arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess'

Check out this question: Triggering a lambda from SNS using cloud-formation?

You need to allow SNS to trigger lambda using AWS::Lambda::Permission

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM