2
votes

I'm creating a logs aggregator lambda to send Cloudwatch logs to a private log analysis service. Given the number of resources used by my employer, it was decided to create a subscription lambda that handles log group subscription to the aggregator.

The solution works fine, but it requires to manually search a resource's log group via amazon console and then invoke the subscription lambda with it.

My question:

Is there a way to, given a resource arn, find which log group is mapped to it? Since I'm using Cloudformation to create resources it is easy to export a resource's arn.

UPDATE

To present an example:

Let's say I have the following arn:

arn:aws:appsync:<REGION>:<ACCOUNTID>apis/z3pihpr4gfbzhflthkyjjh6yvu

which is an Appsync GraphQL API.

What I want it a method (using te API or some automated solution) to get the Cloudwatch log group of that resource.

1
You say given a resource arn. What type of resource? Give an example: input, expected output etc., - helloV

1 Answers

1
votes

You can try the describe-log-groups command. It is available on the cli, must also be there on the API.
To get the names of the log groups you can go with:

aws logs describe-log-groups --query 'logGroups[*].logGroupName' --log-group-name-prefix '/aws/appsync/[name-of-the-resource]'

Output will look like this:

[
"/aws/appsync/[name-of-your-resource]"
]