Manuel
Manuel

Reputation: 15042

How to get CloudWatch Event name in Lambda function?

I have a CloudWatch scheduled event invoking a Lambda function.

The event is currently passing a JSON with some parameters. One of which contains the event name, handwritten, which isn't very elegant and can lead to typos.

enter image description here

I cannot choose to pass the Matched event, as I am also passing some other parameters as JSON.

enter image description here

So I would somehow need to pass the event as a parameter in that JSON object, but I couldn't find any docs about that.

How can I get the invoking event name inside the Lambda function?

Upvotes: 2

Views: 985

Answers (1)

Ashish Modi
Ashish Modi

Reputation: 7770

You can use input transformer which can be used to add your own stuff plus something from the meta data available. In your case

Input path will be

{"ruleName":"$.resources[0]"}

While the Input template will be

{"yourKey": "yourValue", "ruleName": <ruleName>}

The screenshot is here screenshot

And this is how it will be available in your lambda function

{
  yourKey: 'yourValue',
  ruleName: 'arn:aws:events:someregion:someaccountId:rule/testevent'
}

Hope this helps.

Upvotes: 1

Related Questions