Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the lambda function trigger information using aws cli?

I am working with a serverless project and I have only the access to aws cli, so I want to get the trigger information of a function such as event and since I am using a sns topic to trigger the function, I want to get the topic infomation and arn, I tried diffrent options, such as,

list-event-source-mapping - which returns a empty array

get-function: which doesn't hold that value

Do I have means to get the trigger information of a function with aws cli?

like image 470
gokublack Avatar asked Jun 20 '26 06:06

gokublack


1 Answers

In this case, I believe the only way to get that information would be from the get-policy API call as that will contain the resource based policy(AKA trigger) which allows the other service to invoke the Lambda.

The get-event-source-mappings API returns the stream based event sources in the region such as:

  • Kinesis
  • Dynamo
  • SQS

So for example, if I have a lambda function which is configured to be invoked from SNS then the policy returned would be similar to:

aws lambda get-policy --function-name arn:aws:lambda:us-east-1:111122223333:function:YOUR_LAMBDA_NAME_HERE --query Policy --output text | jq '.Statement[0].Condition.ArnLike["AWS:SourceArn"]'

OUTPUT:

"arn:aws:sns:REGION:111122223333:TOPIC_NAME"

Though that assumes that the policy in the Lambda function only has that one statement but if you know the specific statement id then you should be able to select it in jq using a filter

like image 167
jmp Avatar answered Jun 22 '26 00:06

jmp



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!