3

I want to pass parameters to my lambda function invoked by AWS Cloudwatch events. The parameter name is alarmActions and my CFT template for the event rule is as follows:

"LambdaInvokeScheduler": {
            "Type": "AWS::Events::Rule",
            "Properties": {
              "Description": "Scheduled Rule for invoking lambda function",
              "EventPattern": {
                "source": [
                  "aws.ecs"
                ],
                "detail-type": [
                  "ECS Container Instance State Change"
                ],
                "detail": {
                  "clusterArn": [
                    { "Fn::GetAtt": ["WindowsCluster", "Arn"] }
                  ]
                }
              },
              "State": "ENABLED",
              "Targets": [{
                "Arn": { "Fn::GetAtt": ["AlarmCreationLambdaFunction", "Arn"] },
                "Id": "AlarmCreationLambdaFunction",
                "Input": { "Fn::Join" : ["", [ "{ \"alarmActions\": \"", { "Fn::Join" : [":", [ "arn:aws:sns", { "Ref" : "AWS::Region" }, { "Ref" : "AWS::AccountId" }, "CloudWatch"]] }, "\" }"]] }
              }]
            }
          }

I have used the Input parameter to pass a JSON text. There is not much documentation around it. I just wanted to find the right way to do it.

Aditya Nair
  • 514
  • 1
  • 9
  • 18
  • what is sample input for lambda it will be helpful solve your problem. Passing input in CloudFormation is right approach. – Avinash Dalvi Sep 02 '20 at 09:08

1 Answers1

0

I found the solution. I was referring the parameter in lambda in a wrong way.

My lambda function was like this:

def func(event, context, alarmActions)
{
   print(alarmActions)
}

It worked when i made the following update:

def func(event, context)
{
   print(event['alarmActions'])
}
Aditya Nair
  • 514
  • 1
  • 9
  • 18