Git Product home page Git Product logo

aws-inventory's Introduction

aws-inventory

Did your never forget to stop an EC2 instance? Or to delete some unusued AWS resource? I'm sure you did. And only remembering it when getting the bill. I know, AWS Config may help you, but did you ever try? It's prohibitive!

This python script lists all the main resources of your AWS account. This inventory may be uncomplete, but it should help you to find what I call "main" resources that are, in my mind, resources that should affect billing and/or security.

Intended for personal use (even if I added some professional features like logging), and for only one account. For more information on multiple accounts, read the wiki.

Pre-requisites

This program needs Python 3.4 or newer.

AWS CLI must be installed and configured on the system you want to run aws-inventory. You SHOULD use a special account with minimal rights (= those in inventory*.json files). See wiki for more.

Make sure that you have the latest boto3 version. Older versions may lead to signature error with the newest regions or to some malfunction. Further information here : http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html.

How to contribute?

TESTERS WANTED! If you test this code, please send me feedback: I can't test every configuration (especially when there are a lot of items in inventories), so either if it works or not, let me know what is fine and what needs to be corrected (use issues).

Supported AWS services is limited, but I add some regulary. Supported services are detailed here (wiki):

If you want to add services, you're welcome but keep two things in mind:

  • Use the 'dev' branch to commit your changes;
  • Please follow the general coding style and structure (to keep all functionnalities like progression status).

Derived from https://github.com/powerupcloud/AWSInventoryLambda but not forked because it has been too much modified. Rewritten from scratch to be more pythonified.

What's new in the oct-21 version?

Serviced added, not always fully tested (ForeCast, SageMaker, GuardDuty, WAF/WAFv2/WAF-Regional...). See here for the supported services.

What's new in the sept-21 version?

Some services added (docDB, QLDB, containers...) but a very important update with a better handling of non-existant services (some tests added, and HSM v1 deleted). Execution time is now 60-70 sec. (instead of 200-220). There's a bug with 'timestream-write', so there's an ugly "wart" to prevent long timeouts: the get_available_regions() function returns an empty array for this service.

What's new in this version?

This is an attempt to use multithreading in order to accelerate the script. And, at first sight, it looks better: 230 seconds instead of 960 (for the same inventory) on my first test. A lot of services has been added, with some improvements (like for Lightsail).

And in the next one?

I'm working on a visualization tool. It can be useful for infra services (EC2, EFS, VPC, etc.). I don't know yet how far I can go, and what is the best dataviz tool for that. I'm trying with vis.js.

How to use it

This script is intented to be executed from any python environment (and not only as a AWS lambda function as the original script). More information on wiki.

If you like it

This project is open source (GPL-3.0), but took me some time and efforts to design, to code, to make some researches and to test it. I hope you like this script, and that it will be useful for you.

So, this project in donationware (or donateware). It means that you can give me a small fee or contribution for my work. For those who are familiar with RFCs, it's not SHOULD but it's MAY. Think about it especially if you fork the project, but there is no obligation.

For instance, a couple of $ or € can help me buying a dozen of coffee at work! And if you are millionnaire or a big company, please note that the service I use (leetchi.com) accepts millions of $/€, which could be help me with coffees until retirement.

You can donate here: janiko71/aws-inventory on leetchi.com

aws-inventory's People

Contributors

braun1928 avatar dependabot[bot] avatar janiko71 avatar sahu-sunil avatar xp-1000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-inventory's Issues

output format only accept json

Hi

I don't know If this is an issue, but output always is json, and Im interested to use other options like text or table. I config inside AWS cli this option, but I can't see If exist any form to pass this option to the script.

Thanks

empty namespaces still return values

Not a big issue, but I wonder if anyone has a quick solution for it.
I am using this script to generate an inventory for documentation purposes (I save nicely formatted yaml files rather than jsons). I wish to achieve two things

  1. avoid adding empty sections as per below - is there a way to omit those?
ec2: []
ec2-ebs: []
ec2-egpu: []
ec2-eips: []
  1. only return specific fields from an inventory. e.g:
    for EvenBus, I only need 'Name', not a whole blob of 17 lines.

Kind regards
Dawid

working well

Thanks for this project. I like the direction its heading. I was able to get it running, it hung for me the first run, but after I started running it for specific services it now completes fine. I'm struggling with the .json output file trying to find a good way to view it. would love suggestions on that. I wish there was an easy way to run it with multiple AWS accounts. even if I could just pass the credentials as command line variables. I could script it to run several different inventories in sequence.

functions locations confusion

Hi, is there any reason why kms is in iam.py rather than its own module? elb, elbv2 in networking rather than compute? I'm also trying to add IAM inventory, managed to do users list and groups list, now trying to combine the two - can you think of a way to nest one or the other (e.g. users list under group, or group list under each user?) - 'list-users-for-group' from aws' cli is not really helpful here (no common keys?)

Runtime anomalies

Route53 : ends at 95.24% and not 100%. Long execution time.
Hsm: ? Timeout when not existing (in a region).
The script hangs sometimes (throtteling). Account limitation issue?

"Retribution" is wrong word

Hey "retribution" almost always has meaning of "punishment". Your readme file has this word but I'm pretty sure you meant "contribution" or "reward" :)

AWS regions

How can I limit the scan to a specific region ?

I’ve edited the aws-regions.json configuration to the us-east-1 region alone. However when I run a scan for s3 buckets the tool defaults to global region

Request advise

S3_INVENTORY_BUCKET usage ?

Hi,

I'm planning to use it as a lambda, and save the inventory to a s3 bucket.

S3_INVENTORY_BUCKET looks like a variable to define an output s3 bucket adress, but not used. Is it planned or I missed something ?

Why config.global_inventory is empty?

global_inventory = {}

since config.global_inventory list is empty so getting below error

Error :
Traceback (most recent call last):
File "/var/task/call_aws_inventory.py", line 5, in get_aws_inventory
inventory.call_inventory()
File "/var/task/inventory.py", line 123, in call_inventory
inventory[svc] = config.global_inventory[svc]
KeyError: 's3'

sqs queues list is always empty

Hello,

Output for sqs queues is always empty whereas other services work fine (s3, ec2, rds..) and obviously there also have sqs queues on the aws account I test.

Running with --log debug does not provide more information on the error but after re-configure the logger manually I can see the following:

Error while processing sqs, eu-west-3, list_queues. Error: argument of type 'NoneType' is not iterable

Progession error

Progression is KO when sms and emr in services list for inventory.

(venv) C:\Dev\aws-inventory>py inventory.py --service sns emr
----------------------------------------------------------------------------------------------------
Number of services   : 2
Services List        : ['sns', 'emr']
----------------------------------------------------------------------------------------------------

OwnerID : 559583391002 ! 166.67 % ! Region : us-west-2        ! sns (list_platform_applications)

All inventories are done. Duration: 26.137696 seconds

End of processing.

Fail when use parameters

Hi
I'm checking script with parameters profile and services how appears in the wiki but appears error for parameters.

Exception: Unknown argument [--profile]
Exception: Unknown argument [--services]

simply I execute

python3 inventory.py --profile tools --services ec2

Which config is missing?

Issue about region specal endpoint

$ docker run --name zolotnik-015291475736 -v /tmp/aws-inventory/output:/usr/src/app/output -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID_015291475736} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY_015291475736} ${REGISTRY_OVH}/zolotnik:latest python ./inventory.py --services s3 ec2 rds dynamodb ecs cloudwatch route53 elb elbv2 ecr

Number of services : 10
Services List : ['s3', 'ec2', 'rds', 'dynamodb', 'ecs', 'cloudwatch', 'route53', 'elb', 'elbv2', 'ecr']

Exception in thread Thread-20:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/src/app/res/awsthread.py", line 48, in run
config.global_inventory[self.aws_service] = self.function_name(*self.arg)
File "/usr/src/app/res/storage.py", line 114, in get_s3_inventory
for objects in page_objects:
File "/usr/local/lib/python3.8/site-packages/botocore/paginate.py", line 269, in iter
response = self._make_request(current_kwargs)
File "/usr/local/lib/python3.8/site-packages/botocore/paginate.py", line 357, in _make_request
return self._method(**current_kwargs)
File "/usr/local/lib/python3.8/site-packages/botocore/client.py", line 508, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.8/site-packages/botocore/client.py", line 915, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the ListObjectsV2 operation: The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.
Traceback (most recent call last):
File "./inventory.py", line 573, in
inventory[svc] = config.global_inventory[svc]
KeyError: 's3'

Not (yet) Running from CloudShell (AWS or GCP)

Has anybody tried this on Google Cloud Shell or in AWS CloudShell?

I use the following commands to start the project:

pip3 install gives some errors on AWS Cloudshell, but works fine on GCP.

However, both CloudShells leave me with a non-working application:

I get this error:
Traceback (most recent call last): File "inventory.py", line 61, in <module> ownerId = utils.get_ownerID(profile_name) File "/home/jason_dinkel/729121273778/aws-inventory/res/utils.py", line 173, in get_ownerID identity = sts.get_caller_identity() File "/home/jason_dinkel/.local/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/jason_dinkel/.local/lib/python3.7/site-packages/botocore/client.py", line 676, in _make_api_call raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError: An error occurred (ExpiredToken) when calling the GetCallerIdentity operation: The security token included in the request is expired

Now, the token comes from the SSO console for GCP and for AWS, the credentials are built-into the cloudshell, so neither should be the problem.

Also, the AWS Cloudshell shouldn't prompt for a [default] profile.
[cloudshell-user@ip-10-0-28-32 aws-inventory]$ python3 inventory.py
Profile name [default] not found, please check.

If anybody wants to have a look, I'd appreciate it. If I find a solution, I will post the steps.

Thanks.

S3 inventory broken?

ᐅ python inventory.py s3                                                                        
----------------------------------------------------------------------------------------------------
Number of services   : 1
Services List        : ['s3']
----------------------------------------------------------------------------------------------------

Traceback (most recent call last):! Region : global           ! s3 (list_buckets)                    
  File "inventory.py", line 449, in <module>
    inventory[svc] = config.global_inventory[svc]    
KeyError: 's3'

Note that the above error appears after editing line https://github.com/janiko71/aws-inventory/blob/master/inventory.py#L411 to th.join(60)

Script hangs when Internet connection is unstable

When Internet connection is unstable, threads wait forever due to the missing timeout in the underline threading's acquire call (I suppose).

Specifying a timeout will ensure the script to ends at some point, writing the information gathered so far.

Specify a aws profile and see output of script

Hi, I ran the inventory script however it took a long time so I exited. I have about ten accounts in my local aws credentials. I would like to specific --profile for one account. Also a secondary thing is to see the output of the running script if possible. Let me know. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.