Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudWatch Event Rule - Invoke Lambda with Parameter

I am using an AWS CloudWatch Event Rule to invoke a Python Lambda function based on Cron Schedule, which is working fine. Now can I pass a parameter into this Lambda function from CloudWatch Event Rule using AWS CloudFormation? Here is my cfn template:

Step 1: parameter.Schedule=cron(0 21 ? * * *)

Step 2: "Schedule": {
            "Description": "Schedule for the Lambda function (cron or rate)",
            "Type": "String"
         },
          
          
Step 3:  "funcInvokeRule": {
            "Type": "AWS::Events::Rule",
            "Properties": {
                "ScheduleExpression": {"Ref": "Schedule"},
                "Targets": [{
                    "Id": "funcScheduler",
                    "Arn": {"Fn::GetAtt": ["Function","Arn"]}
                }]
             }
          },
like image 643
Agniv Avatar asked Oct 16 '25 15:10

Agniv


1 Answers

The Target property type of AWS::Events::Rule has Input parameter:

Valid JSON text passed to the target. If you use this property, nothing from the event text itself is passed to the target.

There is also InputTransformer which you can use to transform existing input, by for example, adding extra values to it.

Settings to enable you to provide custom input to a target based on certain event data. You can extract one or more key-value pairs from the event and then use that data to send customized input to the target.

like image 89
Marcin Avatar answered Oct 18 '25 08:10

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!