0

How do I list all AWS tagged and untagged resources and delete only cost consumable resources, as soon as the resource reaches the cost threshold?

sparsha_811
  • 9
  • 1
  • 3
  • There is no provided method for obtaining a list of _all_ resources. You would need to write a script to loop through all services in all regions. You should be able to find plenty of examples on the web where people have already written such scripts (eg [JohannesEbke/aws_list_all: List all your AWS resources, all regions, all services.](https://github.com/JohannesEbke/aws_list_all)). – John Rotenstein Nov 23 '19 at 22:12
  • 1
    **See Also**: [Is there a way to list all resources in AWS](https://stackoverflow.com/q/44391817/1366033) – KyleMit Oct 19 '20 at 18:16

1 Answers1

0

You can get the list of resources using AWS Config or its CLI.

aws configservice list-discovered-resources

You can write custom script or lambda along with CloudWatch events to get the cost and usage for this specific API.

Follow this link.

Hassan Murtaza
  • 963
  • 6
  • 15
  • AWS Config is an expensive service, is there a better way to solve this issue? Also can the list of resources (which are exceeding the cost) be extracted and deleted in a child account which is part of an AWS Organisation? – sparsha_811 Nov 22 '19 at 09:27
  • I think you can use this cli command to discover all resources of a region: aws resourcegroupstaggingapi get-resources --region us-west-2 – Hassan Murtaza Nov 22 '19 at 10:14
  • And it's not possible to automatically list resources. But you'll need to write custom script using AWS Cost and Usage APIs. – Hassan Murtaza Nov 22 '19 at 10:15
  • Is there a way through lambda to delete resources automatically? (which are exceeding the cost) ? – sparsha_811 Nov 22 '19 at 10:28
  • Yes, you can either use aws-sdk in Nodejs or boto3 in Python to automate this task with Lambda. – Hassan Murtaza Nov 22 '19 at 12:16