How to find for aws log groups the corresponding ressource?

Viewed 920

due to huge costs in our environment, I have a task to create a lambda to tag all log groups like corresponding resources (the source of these log groups). However, I am facing a challenge to identify the resource arn of log groups. There are many logs in our environment like logs for lambda, logs for elastic-beanstalk, logs for ec2. But how can I match the log group with the corresponding resource? I would appreciate any help very much!

1 Answers

I would try using describe-log-groups. To use it you'll need to work your way "backwards" by going from resources to the log-groups, but I can't think of any other way at the moment.

aws logs describe-log-groups --query 'logGroups[*].arn' --log-group-name-prefix '/aws/lambda/[name-of-your-lambda]'

Output:

[
"arn:aws:logs:[region]:[account-id]:log-group:/aws/lambda/[name-of-your-lambda]:*"
]

Hope that helps.

Related