8

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?

2
  • Are you wanting to retrieve a the details of an existing trigger? Wouldn't you use get-event-source-mappings? Commented Jun 23, 2019 at 0:55
  • 3
    Three years later and it seems indeed AWS still does not support listing (nor creating) Lambda function triggers; the aws CLI simply has a blank spot there and all the docs I could find are about using the AWS Console to configure triggers in selected source types, e.g. CloudFront, Code Commit. Brickwall for my current approach 😡 Commented Oct 7, 2022 at 14:09

1 Answer 1

11

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.