jckuester / awsls

A list command for AWS resources
MIT License
838 stars 54 forks source link

Ability to list all resources by ARN #15

Open klauern opened 4 years ago

klauern commented 4 years ago

I've been doing some more exploratory work to discover all of our resources and perform some tagging efforts. The Resource Groups Tagging API supports a TagResources call that allows you to apply tags en masse with a list of ARNs.

https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_TagResources.html

I was hoping to use this tool to list all the resources, apply some tags to them, and then do other automation around those tags. However, it doesn't appear that there's a standard way to return the ARN for the resource that you are listing. I would like to be able to return ARN's for all of these resource types, so I can pass that in to downstream tools.

jckuester commented 3 years ago

Hi @klauern,

sorry, for answering so late.

You could try

awsls "*" -a arn

to output the ARN attribute for all resources that have one (otherwise the output is N/A). Note that the first 5 attribute columns in the output are always the same: TYPE ID PROFILE REGION CREATED, and the 6th attribute is then the ARN.

You could then pipe the output then through some tools like awk to get just the ARNs. Did you try something like this?

jckuester commented 3 years ago

Hi @klauern again,

I added JSON output support in v0.10.0. This simplifies to just returning the ARN; what you can do now is

awsls <resource_type> -a arn --json | jq '.[] | .arn'

Does this help?

anovero123 commented 3 years ago

May i ask what the status of this request is?

The job stuck with unavailable service: awsls "*" --profiles=zzh --regions=us-east-1 -a arn --json | jq '.[] | .arn'

Error aws_globalaccelerator_accelerator: operation error Global Accelerator: ListAccelerators, exceeded maximum number of attempts, 3, https response error StatusCode: 0, RequestID: , request send failed, Post "https://globalaccelerator.us-east-1.amazonaws.com/": Service Unavailable

christonog commented 2 years ago

I also ran into @anovero123's issue just now. Running in debug mode shows:

   • start listing resources   profile= region=us-east-1 type=aws_globalaccelerator_accelerator
Error aws_globalaccelerator_accelerator: operation error Global Accelerator: ListAccelerators, exceeded maximum number of attempts, 3, https response error StatusCode: 0, RequestID: , request send failed, Post "https://globalaccelerator.us-east-1.amazonaws.com/": dial tcp: lookup globalaccelerator.us-east-1.amazonaws.com on [2605:a601:a6dc:7400::1]:53: no such host
   • start listing resources   profile= region=us-east-1 type=aws_glue_crawler
   • start listing resources   profile= region=us-east-1 type=aws_glue_dev_endpoint

Seems to hang at the aws_glue_dev_endpoint resource listing.