Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add triggers for a AWS Lambda function created using a CloudFormation template?

I am trying to create a lambda function from a CloudFormation template based on this example:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-lambda.html

As can be seen from this link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

there is no way to add a trigger for the lambda function (like a S3 upload trigger).

Is there a workaround to specify the trigger while writing the template?

like image 270
trans1st0r Avatar asked Jun 15 '26 20:06

trans1st0r


1 Answers

You can use cloudwatch rule to trigger your lambda function :

    AWSTemplateFormatVersion: '2010-09-09'
    Resources:
      MyCloudWatchRule:
        Type: "AWS::Events::Rule"
        Properties:
          Description: "Rule to trigger lambda"
          Name: "MyCloudWatchRule"
          EventPattern: <Provide Valid JSON Event pattern>
          State: "ENABLED"
          Targets:
            - Arn: "arn:aws:lambda:us-west-2:12345678:function:MyLambdaFunction"
              Id: "1234567-acvd-awse-kllpk-123456789"

Ref :

  • https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#aws-resource-events-rule-syntax
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html
like image 124
Suresh Kumar Avatar answered Jun 18 '26 00:06

Suresh Kumar