Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list triggers associated with AWS Lambda function using Java SDK

Inside AWS Lambda console if you click on Triggers tab it will show you list of triggers if any triggers are configured for that lambda function. How to get the list of configured triggered using Java SDK for AWS?

Thanks.

like image 499
Arpan Solanki Avatar asked Apr 27 '17 18:04

Arpan Solanki


1 Answers

You can get the list of triggers, but it is not a straightforward task. I have managed to reproduce the behavior of the console in code. I code in Node.js, but using these methods in the Java SDK will give you the same results.

1) Use the Lambda getPolicy() method to retrieve the Policy JSON (the same one displayed in the console under Triggers / View Function Policy).

2) Parse the JSON and use the "Statement"/"Condition"/"ArnLike"/"AWS:SourceArn" elements to parse out the S3 bucket names for the triggers.

3) Use the S3 getBucketNotificationConfiguration() method to retrieve the list of triggers for each bucket found in 2).

4) Parse the result from 3) and search through the LambdaFunctionConfigurations nodes for the matching LambdaFunctionArn of your Lambda. The matching nodes have the details of any triggers from the S3 buckets from 2) to your Lambda.

I would assume that triggers from other AWS sources than S3 buckets can be found similarly, but my use case was only for S3 buckets.

Note: The answer provided by johni on 29-Apr is incorrect. When I attempted it I learned that this method only returns Kinesis events. Triggers from other AWS sources are only visible in the Lambda Function's Policy JSON.

like image 172
Corey A. Henderson Avatar answered Nov 05 '22 04:11

Corey A. Henderson