├── requirements.txt ├── iam ├── aws_size_no_sensitive.json └── aws_size_read_policy.json ├── README.md ├── LICENSE └── aws-size.py /requirements.txt: -------------------------------------------------------------------------------- 1 | args>=0.1.0 2 | boto3>=1.39.12 3 | botocore>=1.39.12 4 | questionary>=2.1.0 -------------------------------------------------------------------------------- /iam/aws_size_no_sensitive.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "AwsSizeReadOnly", 6 | "Effect": "Allow", 7 | "Action": [ 8 | "iam:ListPolicies", 9 | "iam:GetPolicy", 10 | "iam:GetPolicyVersion", 11 | "iam:ListRoles", 12 | "iam:ListAttachedRolePolicies", 13 | "iam:GetRole", 14 | "iam:ListGroups", 15 | "iam:ListUsers", 16 | "iam:ListGroupPolicies", 17 | "iam:ListUserPolicies", 18 | "iam:ListRolePolicies", 19 | "iam:GetGroupPolicy", 20 | "iam:GetUserPolicy", 21 | "iam:GetRolePolicy", 22 | "ec2:DescribeInstances", 23 | "ec2:DescribeInstanceAttribute", 24 | "ec2:DescribeVpcEndpoints", 25 | "s3:ListAllMyBuckets", 26 | "s3:GetBucketPolicy", 27 | "organizations:ListPolicies", 28 | "organizations:DescribePolicy", 29 | "servicequotas:GetServiceQuota", 30 | "kms:DescribeKey" 31 | ], 32 | "Resource": "*" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /iam/aws_size_read_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "AwsSizeReadOnly", 6 | "Effect": "Allow", 7 | "Action": [ 8 | "iam:ListPolicies", 9 | "iam:GetPolicy", 10 | "iam:GetPolicyVersion", 11 | "iam:ListRoles", 12 | "iam:ListAttachedRolePolicies", 13 | "iam:GetRole", 14 | "iam:ListGroups", 15 | "iam:ListUsers", 16 | "iam:ListGroupPolicies", 17 | "iam:ListUserPolicies", 18 | "iam:ListRolePolicies", 19 | "iam:GetGroupPolicy", 20 | "iam:GetUserPolicy", 21 | "iam:GetRolePolicy", 22 | "ec2:DescribeInstances", 23 | "ec2:DescribeInstanceAttribute", 24 | "s3:ListAllMyBuckets", 25 | "s3:GetBucketPolicy", 26 | "organizations:ListPolicies", 27 | "organizations:DescribePolicy", 28 | "servicequotas:GetServiceQuota", 29 | "kms:DescribeKey" 30 | ], 31 | "Resource": "*" 32 | }, 33 | { 34 | "Sid": "AwsSizeParamaterAndSecretSize", 35 | "Effect": "Allow", 36 | "Action": [ 37 | "kms:Decrypt", 38 | "ssm:DescribeParameters", 39 | "ssm:GetParameter", 40 | "lambda:ListFunctions", 41 | "secretsmanager:ListSecrets", 42 | "secretsmanager:GetSecretValue" 43 | ], 44 | "Resource": "*" 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-size 2 | Checks Hard to Find Size Limits and Usage for AWS and can provide advance warning to teams about resource limits in AWS before it's too late. Usage of these limits are not covered by AWS provided tooling such as Service Quotas and Trusted Advisor. 3 | 4 | For support or questions, we can be reached at info@fogsecurity.io. 5 | Release Blog: [https://www.fogsecurity.io/blog/aws-size-release](https://www.fogsecurity.io/blog/aws-size-release) 6 | 7 | ## Overview 8 | 9 | AWS services and resources have limits that can impact development. These limits (sometimes referred to as Service Quotas) can sometimes be adjustable (soft limits) or not (hard limits). In some cases, these can make development difficult as running into a limit late can result in larger or risky architectural changes. While AWS offers tooling to manage these and view visibility such as Service Quotas, Trusted Advisor, and more - these tools do not account for all limits and often refer to account or resource # limits, not necessarily limits within resources. Even open source tooling we looked at focuses on similar limits and Trusted Advisor coverage. aws-size addresses this gap in coverage and visibility. 10 | 11 | aws-size's current coverage: IAM, Organizations, EC2, S3, Systems Manager, Lambda, Secrets Manager, VPC 12 | 13 | Note: aws-size does not currently cover any service limit supported by Trusted Advisor such as account limits (IAM roles per account). If there's interest to have aws-size cover all service limits, please vote on the corresponding GitHub issue: [https://github.com/FogSecurity/aws-size/issues/59](https://github.com/FogSecurity/aws-size/issues/59). 14 | 15 | Imagine a scenario where someone is trying to apply least privilege and has appropriately used condition keys, granular IAM actions, and resources in their IAM policies. They may need to add another statement or action, but if they're out of character space - they will need to think creatively on how to adjust the policy. This tool will help bring visibility into those limits. Example workarounds in IAM are using wildcards (which can be dangerous), or splitting into multiple policies. These changes can be complex and can result in different configurations or unintended results. 16 | 17 | ## Running aws-size 18 | 19 | Prerequisites: 20 | * Python 21 | * AWS Credentials 22 | 23 | We recommend least privilege when running aws-size and using short-term credentials. aws-size does not require any sort of write permissions. AWS provided managed policies that can work with aws-size include ReadOnlyAccess and SecurityAudit. The ViewOnlyAccess policy does not have the appropriate permissions to view usage of certain resources. 24 | 25 | If you are using aws-size to scan parameter or secret resources (Secrets Manager or Systems Manager Parameter Store), AWS provided managed policies may not work. Secrets Manager requires `secretsmanager:GetSecretValue` which is not in any of the aforementioned AWS provided managed policies. Parameter Store requires `ssm:GetParameter` which is not in SecurityAudit nor ViewOnlyAccess. Additionally, certain resources will require `kms:Decrypt` if encrypted with a KMS key to retrieve length of data. 26 | 27 | IMPORTANT: aws-size has the ability to scan for potentially sensitive information such as Lambda Environment Variables, Secrets Manager Secrets, and Parameter Store Parameters. For accurate sizing and limit calculations, aws-size will need access to the underlying information and resource values. We recommend ensuring access to aws-size, aws-size's credentials are secure, and that any privileged permissions used by aws-size are not shared to other unintended use cases. Aws-size can be run without those capabilities and thus if you do not have a need or desire to scan for potentially sensitive information, we recommend ensuring those corresponding IAM permissions are not given to aws-size. See the [IAM reference](iam/) for additional references. 28 | 29 | If concerned about scanning secret values, we recommend not granting aws-size access to sensitive variables and only running aws-size on non-sensitive resources. 30 | 31 | A reference IAM policy for aws-size (all features) can be found [here](iam/aws_size_read_policy.json). 32 | 33 | To install required libraries, `pip3 install -r requirements.txt` can be run. 34 | 35 | To run aws-size, the following command can be run: 36 | 37 | ``` 38 | python3 aws-size.py --profile --region us-east-1 39 | ``` 40 | 41 | ``` 42 | ? Select a resource limit (Use arrow keys) 43 | » AWS IAM Managed Policies 44 | AWS IAM Role Trust Policy 45 | AWS IAM Managed Policies Per Role 46 | AWS IAM Role Inline Policies 47 | AWS IAM User Inline Policies 48 | AWS IAM Group Inline Policies 49 | AWS EC2 User Data 50 | S3 Bucket Policy 51 | Organizations SCPs 52 | Organizations RCPs 53 | Organizations Declarative Policies 54 | Organizations AI Services Opt-out Policies 55 | Organizations Tag Policies 56 | Organizations Backup Policies 57 | Organizations Chat Applications Policies 58 | SSM Parameter Store Parameters 59 | Lambda Environment Variables 60 | Secrets Manager Secrets 61 | VPC Endpoint Policies 62 | ``` 63 | 64 | Note: Region is only necessary if choosing resources that are regional such as EC2 instances and user data. IAM is a global service. 65 | 66 | Example output: 67 | 68 | ``` 69 | Customer Managed Policies Scanned: 82 70 | Customer Managed Policies with usage over 90%: 2 71 | 72 | List of policies with more than 90% character usage: 73 | arn:aws:iam::123412341234:policy/ 74 | Policy Usage: 90.48% 75 | Characters Left: 585 76 | ``` 77 | 78 | ### Customization: Setting Threshold 79 | 80 | By default, aws-size reports resources with equal or over than 90% usage. For customization, aws-size supports the `--threshold` argument. This argument takes a number between 0 and 1 inclusive to set the threshold of resources for reporting. 81 | 82 | For example, setting the threshold to 0.75 will report resources with 75% or more usage. 83 | 84 | ``` 85 | python3 aws-size.py --profile --threshold 0.75 86 | ``` 87 | 88 | If you want to return all resources, set the threshold to 0. Additionally, threshold can be set to all. 89 | 90 | Example commands: 91 | 92 | ``` 93 | python3 aws-size.py --profile --threshold all 94 | python3 aws-size.py --profile --threshold 0 95 | ``` 96 | 97 | ### Saving Output to File 98 | 99 | aws-size now supports saving the run results to a json file via the `--output` argument. To save, use the `--output` argument followed by the file name. Results are stored with metadata from the run. 100 | 101 | Example command: 102 | ``` 103 | python3 aws-size.py --profile --threshold 0.75 --output aws-size-output.json 104 | ``` 105 | 106 | Example of file structure is as follows: 107 | ``` 108 | { 109 | "metadata": { 110 | "resource": "AWS IAM Managed Policies", 111 | "threshold": 0, 112 | "timestamp": "2025-08-07 15:35:58" 113 | }, 114 | "results": [ 115 | { 116 | "arn": "arn:aws:iam::123412341234:policy/aws-size-test-policy", 117 | "name": "aws-size-test-policy", 118 | "usage": 0.0832, 119 | "charleft": 5633 120 | }, 121 | ... 122 | ] 123 | } 124 | ``` 125 | 126 | 127 | ## Coverage 128 | 129 | | Service | Resource | Limit | Limit Size | Service Quota Coverage | Service Quota Visibility | Trusted Advisor Visibility | Adjustable | 130 | | ------- | -------- | ----- | ---------- | ---------------------- | ------------------------ | -------------------------- | ---------- | 131 | | IAM | Managed Policies | Policy Length | 6,144 characters | L-ED111B8C | No | No | No | 132 | | IAM | IAM Roles | Role trust policy length | 2,048 characters | L-C07B4B0D | No | Yes* | Yes | 133 | | IAM | IAM Roles | Managed Policies Per Role | 10 | L-0DA4ABF3 | Yes | Yes | No | 134 | | IAM | IAM Roles | Inline Policy Size | 10,240 characters | No | No | No | No | 135 | | IAM | IAM Users | Inline Policy Size | 2,048 characters | No | No | No | No | 136 | | IAM | IAM Groups | Inline Policy Size | 5,120 characters | No | No | No | No | 137 | | EC2 | Instance | User Data Size | 16 KB | No | No | No | No | 138 | | S3 | Bucket | Bucket Policy Size | 20 KB | L-748707F3 | No | No | No | 139 | | Organizations | SCPs | Document Size | 5,120 characters | L-C48BCE79 | No | No | No | 140 | | Organizations | RCPs | Document Size | 5,120 characters | No | No | No | No | 141 | | Organizations | Declarative Policies | Document Size | 10,000 characters | No | No | No | No | 142 | | Organizations | AI Services Opt-out Policies | Document Size | 2,500 characters | No | No | No | No | 143 | | Organizations | Tag Policies | Document Size | 10,000 characters | No | No | No | No | 144 | | Organizations | Backup Policies | Document Size | 10,000 characters | No | No | No | No | 145 | | Organizations | Chat Application Policies | Document Size | 10,000 characters | No | No | No | No | 146 | | Systems Manager | Parameter Store Standard Parameter | Size | 4 KB | L-BCC99751 | No | No | No | 147 | | Systems Manager | Parameter Store Advanced Parameter | Size | 8 KB | L-CECCEB04 | No | No | No | 148 | | Lambda | Lambda Environment Variables | Combined Size | 4 KB | L-6581F036 | No | No | No | 149 | | Secrets Manager | Secret | Value Size | 65,536 bytes | L-2F24C883 | No | No | No | 150 | | VPC (EC2) | Interface VPC Endpoint Policy | Policy Size | 20,480 characters | L-3248932A | No | No | No | 151 | 152 | Note: Yes* for service quota visibility means we do see some visibility. This seems limited to resources that have been recently updated. 153 | 154 | ### IAM Managed Policies (Global) 155 | 156 | Limit: 6,144 characters 157 | Note: white space doesn't count 158 | [AWS Documentation on IAM Limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html). 159 | 160 | ### IAM Role Trust Policy (Global) 161 | 162 | Limit: 2,048 characters. 163 | Note: white space doesn't count. This limit is adjustable up to 4,096. 164 | [AWS Documentation on IAM Limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html). 165 | 166 | ### IAM Managed Policies Per Role (Global) 167 | 168 | Limit: 10 Managed Policies Per Role. 169 | Note: There is limited support in CloudWatch and Service Quotas. 170 | 171 | ### IAM Role Inline Policy Size (Global) 172 | 173 | Limit: 10,240 characters. 174 | Note: This is the aggregate policy size (sum of all inline policies) 175 | [AWS Documentation on IAM Limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html). 176 | 177 | ### IAM User Inline Policy Size (Global) 178 | 179 | Limit: 2,048 characters. 180 | Note: This is the aggregate policy size (sum of all inline policies) 181 | [AWS Documentation on IAM Limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html). 182 | 183 | ### IAM Group Inline Policy Size (Global) 184 | 185 | Limit: 5,120 characters. 186 | Note: This is the aggregate policy size (sum of all inline policies) 187 | [AWS Documentation on IAM Limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html). 188 | 189 | ### EC2 User Data (Region Specific) 190 | 191 | Limit: 16 KB 192 | Note: 16 KB is the limit for unencoded. EC2 encodes user data. 193 | [EC2 User Data Documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) 194 | 195 | ### S3 Bucket Policy Size (Region Specific) 196 | 197 | Limit: 20 KB 198 | Note: AWS does some normalization on bucket policies. aws-size will approximate the normalization - the numbers may be slighty different. 199 | 200 | ### AWS Organizations Service Control Policies (Global) 201 | 202 | Limit: 5,120 characters 203 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 204 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 205 | 206 | ### AWS Organizations Resource Control Policies (Global) 207 | 208 | Limit: 5,120 characters 209 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 210 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 211 | 212 | ### AWS Organizations Declarative Policies (Global) 213 | 214 | Limit: 10,000 characters 215 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 216 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 217 | 218 | ### AWS Organizations AI Services Opt-out Policies (Global) 219 | 220 | Limit: 2,500 characters 221 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 222 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 223 | 224 | ### AWS Organizations Tag Policies (Global) 225 | 226 | Limit: 10,000 characters 227 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 228 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 229 | 230 | ### AWS Organizations Backup Policies (Global) 231 | 232 | Limit: 10,000 characters 233 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 234 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 235 | 236 | ### AWS Organizations Chat Application (Q) Policies (Global) 237 | 238 | Limit: 10,000 characters 239 | Note: If policies are saved via CLI or SDK, white space is preserved. This operation can be called from the management account or a member account if proper permissions are delegated. 240 | [Organizations Limits Documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_reference_limits.html#min-max-values) 241 | 242 | ### Systems Manager Parameter Store Parameter (Region Specific) 243 | 244 | Limit: 4 KB (Standard) 245 | Limit: 8 KB (Advanced) 246 | Note: Decryption may be necessary to determine accurate size of parameters. 247 | 248 | ### Lambda Environment Variables (Region Specific) 249 | 250 | Limit: 4 KB 251 | Note: Decryption may be necessary to determine accurate size of environment variables. The 4 KB limit is a combined limit for all variables. 252 | 253 | ### Secrets Manager Secrets (Region Specific) 254 | 255 | Limit: 65,536 bytes 256 | Note: To accurately determine size of secrets, `secretsmanager:GetSecretValue` and `kms:Decrypt` may be needed. Check IAM permissions for aws-size. 257 | 258 | ### VPC Endpoint Policies (Region Specific) 259 | 260 | Limit: 20,480 characters (including white space) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /aws-size.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import boto3 3 | import questionary 4 | import base64 5 | import sys 6 | import json 7 | from datetime import datetime 8 | 9 | parser = argparse.ArgumentParser(prog='AWS Size') 10 | 11 | parser.add_argument("--profile") 12 | parser.add_argument("--threshold", help='Set threshold for reporting (between 0 and 1). Default is 90%') 13 | parser.add_argument("--region") 14 | parser.add_argument("--output", help='Output file to save results.', default=None) 15 | 16 | args = parser.parse_args() 17 | 18 | supported_limits = [ 19 | "AWS IAM Managed Policies", 20 | "AWS IAM Role Trust Policy", 21 | "AWS IAM Managed Policies Per Role", 22 | "AWS IAM Role Inline Policies", 23 | "AWS IAM User Inline Policies", 24 | "AWS IAM Group Inline Policies", 25 | "AWS EC2 User Data", 26 | "S3 Bucket Policy", 27 | "Organizations SCPs", 28 | "Organizations RCPs", 29 | "Organizations Declarative Policies", 30 | "Organizations AI Services Opt-Out Policies", 31 | "Organizations Tag Policies", 32 | "Organizations Backup Policies", 33 | "Organizations Chat Applications Policies", 34 | "SSM Parameter Store Parameters", 35 | "Lambda Environment Variables", 36 | "Secrets Manager Secrets", 37 | "VPC Endpoint Policies" 38 | ] 39 | 40 | limit = questionary.select( 41 | "Select a resource limit", 42 | choices=supported_limits, 43 | ).ask() 44 | 45 | try: 46 | if args.threshold: 47 | if args.threshold == 'all': 48 | threshold = 0 49 | else: 50 | threshold = float(args.threshold) 51 | if threshold > 1 or threshold < 0: 52 | print("Threshold must be a number between 0 and 1. Running aws-size with default of 90%") 53 | threshold = 0.90 54 | 55 | else: 56 | threshold = 0.90 57 | except: 58 | print("Threshold must be a number between 0 and 1. Running aws-size with default of 90%") 59 | threshold = 0.90 60 | 61 | def save_output_to_file(resources): 62 | if args.output: 63 | 64 | output = {} 65 | 66 | output['metadata'] = { 67 | 'resource': limit, 68 | 'threshold': threshold, 69 | 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S") 70 | } 71 | 72 | output['results'] = resources 73 | 74 | with open(args.output, 'w') as f: 75 | json.dump(output, f, indent=4) 76 | 77 | if limit == 'AWS IAM Managed Policies': 78 | 79 | try: 80 | session = boto3.Session(profile_name = args.profile) 81 | iam_client = session.client('iam') 82 | except: 83 | print("Potential authentication issue: check credentials and try again") 84 | sys.exit() 85 | 86 | try: 87 | iam_policies_results = [ 88 | iam_client.get_paginator('list_policies') 89 | .paginate(Scope='Local' 90 | ) 91 | .build_full_result() 92 | ] 93 | except: 94 | print("Issue with listing IAM managed policies") 95 | sys.exit() 96 | 97 | customer_managed_policies = iam_policies_results[0]['Policies'] 98 | managed_policies_stats = [] 99 | warning_policies = [] 100 | 101 | for managed_policy in customer_managed_policies: 102 | version = managed_policy['DefaultVersionId'] 103 | arn = managed_policy['Arn'] 104 | name = managed_policy['PolicyName'] 105 | 106 | try: 107 | policy = iam_client.get_policy_version( 108 | PolicyArn=arn, 109 | VersionId=version 110 | ) 111 | 112 | policy_doc = policy['PolicyVersion']['Document'] 113 | 114 | str_policy = json.dumps(policy_doc, indent=None, separators=(',', ':')) 115 | 116 | #Strip white space 117 | stripped_str_policy = str_policy.replace(" ", "") 118 | char_count = len(stripped_str_policy) 119 | 120 | usage = round(char_count / 6144, 4) 121 | char_left = 6144 - len(stripped_str_policy) 122 | 123 | if usage >= threshold: 124 | warning_policies.append({ 125 | 'arn': arn, 126 | 'name': name, 127 | 'usage': usage, 128 | 'charleft': char_left 129 | }) 130 | 131 | except: 132 | print(f"Issue processing policy: {arn}") 133 | 134 | #Eventually standardize output here 135 | #Output Section 136 | print("Customer Managed Policies Scanned: " + str(len(managed_policies_stats))) 137 | print(f"Customer Managed Policies with usage over {threshold:.2%} " + str(len(warning_policies))) 138 | print('\n') 139 | 140 | if len(warning_policies) > 0: 141 | print(f"List of policies with more than {threshold:.2%} character usage: ") 142 | 143 | for policy in warning_policies: 144 | print(policy['arn']) 145 | print(f"Policy Usage: {policy['usage']:.2%}") 146 | print("Characters Left: " + str(policy['charleft']) + '\n') 147 | 148 | save_output_to_file(warning_policies) 149 | 150 | elif limit == 'AWS IAM Role Trust Policy': 151 | try: 152 | session = boto3.Session(profile_name = args.profile) 153 | iam_client = session.client('iam') 154 | 155 | #Hard coded Service Quota Region 156 | sq_client = session.client('service-quotas', region_name = 'us-east-1') 157 | except: 158 | print("Potential authentication issue: check credentials and try again") 159 | sys.exit() 160 | 161 | try: 162 | trust_policy_quota = sq_client.get_service_quota( 163 | ServiceCode='iam', 164 | QuotaCode='L-C07B4B0D' 165 | ) 166 | except: 167 | print("Error retrieving Service Quota for IAM") 168 | sys.exit() 169 | 170 | try: 171 | iam_roles_results = [ 172 | iam_client.get_paginator('list_roles') 173 | .paginate() 174 | .build_full_result() 175 | ] 176 | except: 177 | print("Issue with listing IAM roles") 178 | sys.exit() 179 | 180 | 181 | role_trust_quota = trust_policy_quota['Quota']['Value'] 182 | roles = iam_roles_results[0]['Roles'] 183 | 184 | warning_roles = [] 185 | 186 | for role in roles: 187 | arn = role['Arn'] 188 | name = role['RoleName'] 189 | 190 | try: 191 | trust_policy = iam_client.get_role(RoleName=name) 192 | trust_policy = trust_policy['Role']['AssumeRolePolicyDocument'] 193 | 194 | str_trust_policy = json.dumps(trust_policy, indent=None, separators=(', ', ':')) 195 | 196 | stripped_str_policy = str_trust_policy.replace(" ", "") 197 | char_count = len(stripped_str_policy) 198 | 199 | usage = round(char_count / role_trust_quota, 4) 200 | char_left = role_trust_quota - char_count 201 | 202 | if usage >= threshold: 203 | warning_roles.append({ 204 | 'arn': arn, 205 | 'name': name, 206 | 'usage': usage, 207 | 'charleft': char_left 208 | }) 209 | 210 | except: 211 | print(f"Issue processing role: {arn}") 212 | 213 | #Eventually standardize output here 214 | #Output Section 215 | print("IAM Roles Scanned: " + str(len(roles))) 216 | print(f"IAM Roles with Trust Policy usage over {threshold:.2%} " + str(len(warning_roles))) 217 | print('\n') 218 | 219 | if len(warning_roles) > 0: 220 | print(f"List of roles with more than {threshold:.2%} trust policy length character usage: ") 221 | 222 | for role in warning_roles: 223 | print(role['arn']) 224 | print(f"Trust Policy Usage: {role['usage']:.2%}") 225 | print("Characters Left: " + str(role['charleft']) + '\n') 226 | 227 | save_output_to_file(warning_roles) 228 | 229 | elif limit == "AWS IAM Managed Policies Per Role": 230 | 231 | try: 232 | session = boto3.Session(profile_name = args.profile) 233 | iam_client = session.client('iam') 234 | 235 | sq_client = session.client('service-quotas', region_name = 'us-east-1') 236 | except: 237 | print("Potential authentication issue: check credentials and try again") 238 | sys.exit() 239 | 240 | try: 241 | attached_policies_quota = sq_client.get_service_quota( 242 | ServiceCode='iam', 243 | QuotaCode='L-0DA4ABF3' 244 | ) 245 | except: 246 | print("Error retrieving Service Quota for IAM") 247 | sys.exit() 248 | 249 | try: 250 | iam_roles_results = [ 251 | iam_client.get_paginator('list_roles') 252 | .paginate() 253 | .build_full_result() 254 | ] 255 | except: 256 | print("Issue with listing IAM roles") 257 | sys.exit() 258 | 259 | attached_policies_quota = attached_policies_quota['Quota']['Value'] 260 | roles = iam_roles_results[0]['Roles'] 261 | warning_roles = [] 262 | 263 | for role in roles: 264 | arn = role['Arn'] 265 | name = role['RoleName'] 266 | 267 | try: 268 | attached_policies = iam_client.list_attached_role_policies(RoleName=name) 269 | attached_policies_count = len(attached_policies['AttachedPolicies']) 270 | usage = round(attached_policies_count / attached_policies_quota, 4) 271 | 272 | if usage >= threshold: 273 | warning_roles.append({ 274 | 'arn': arn, 275 | 'name': name, 276 | 'usage': usage, 277 | 'policies_left': attached_policies_quota - attached_policies_count 278 | }) 279 | 280 | except: 281 | print(f"Issue processing role: {arn}") 282 | 283 | #Eventually standardize output here 284 | #Output Section 285 | print("IAM Roles Scanned: " + str(len(roles))) 286 | print(f"IAM Roles with more than 10 attached policies: " + str(len(warning_roles))) 287 | print('\n') 288 | 289 | if len(warning_roles) > 0: 290 | print("List of roles with more than 10 attached policies: ") 291 | 292 | for role in warning_roles: 293 | print(role['arn']) 294 | print(f"Role Name: {role['name']}") 295 | print(f"Attached Policies Usage: {role['usage']}\n") 296 | print(f"Policies Left: {role['policies_left']}\n") 297 | 298 | save_output_to_file(warning_roles) 299 | 300 | elif limit == "AWS IAM Role Inline Policies": 301 | try: 302 | session = boto3.Session(profile_name = args.profile) 303 | iam_client = session.client('iam') 304 | except: 305 | print("Potential authentication issue: check credentials and try again") 306 | sys.exit() 307 | 308 | try: 309 | iam_roles_results = [ 310 | iam_client.get_paginator('list_roles') 311 | .paginate() 312 | .build_full_result() 313 | ] 314 | except: 315 | print("Issue with listing IAM roles") 316 | sys.exit() 317 | 318 | roles = iam_roles_results[0]['Roles'] 319 | warning_roles = [] 320 | 321 | for role in roles: 322 | arn = role['Arn'] 323 | name = role['RoleName'] 324 | 325 | role_inline_policy_size = 0 326 | 327 | try: 328 | role_inline_policies_results = [ 329 | iam_client.get_paginator('list_role_policies') 330 | .paginate(RoleName=name) 331 | .build_full_result() 332 | ] 333 | 334 | if role_inline_policies_results[0].get('PolicyNames'): 335 | inline_policies = role_inline_policies_results[0]['PolicyNames'] 336 | else: 337 | inline_policies = [] 338 | 339 | for inline_policy in inline_policies: 340 | 341 | policy = iam_client.get_role_policy( 342 | RoleName=name, 343 | PolicyName=inline_policy 344 | ) 345 | 346 | policy_doc = policy['PolicyDocument'] 347 | 348 | str_policy = json.dumps(policy_doc, indent=None, separators=(',', ':')) 349 | 350 | #Strip white space 351 | stripped_str_policy = str_policy.replace(" ", "") 352 | char_count = len(stripped_str_policy) 353 | 354 | role_inline_policy_size += char_count 355 | 356 | usage = round(role_inline_policy_size / 10240, 4) 357 | char_left = 10240 - role_inline_policy_size 358 | 359 | if usage >= threshold: 360 | warning_roles.append({ 361 | 'arn': arn, 362 | 'name': name, 363 | 'usage': usage, 364 | 'charleft': char_left 365 | }) 366 | 367 | except: 368 | print("Issue with listing inline policies for role: " + name) 369 | continue 370 | 371 | #Eventually standardize output here 372 | #Output Section 373 | print("IAM Roles Scanned: " + str(len(roles))) 374 | print(f"IAM Roles with inline policy usage over {threshold:.2%} " + str(len(warning_roles))) 375 | print('\n') 376 | 377 | if len(warning_roles) > 0: 378 | print(f"List of roles with more than {threshold:.2%} inline policy character usage: ") 379 | 380 | for role in warning_roles: 381 | print(role['arn']) 382 | print(f"Role Name: {role['name']}") 383 | print(f"Inline Policy Usage: {role['usage']:.2%}") 384 | print("Characters Left: " + str(role['charleft']) + '\n') 385 | 386 | save_output_to_file(warning_roles) 387 | 388 | elif limit == "AWS IAM User Inline Policies": 389 | try: 390 | session = boto3.Session(profile_name = args.profile) 391 | iam_client = session.client('iam') 392 | except: 393 | print("Potential authentication issue: check credentials and try again") 394 | sys.exit() 395 | 396 | try: 397 | iam_users_results = [ 398 | iam_client.get_paginator('list_users') 399 | .paginate() 400 | .build_full_result() 401 | ] 402 | except: 403 | print("Issue with listing IAM users") 404 | sys.exit() 405 | 406 | users = iam_users_results[0]['Users'] 407 | warning_users = [] 408 | 409 | for user in users: 410 | arn = user['Arn'] 411 | name = user['UserName'] 412 | 413 | user_inline_policy_size = 0 414 | 415 | try: 416 | user_inline_policies_results = [ 417 | iam_client.get_paginator('list_user_policies') 418 | .paginate(UserName=name) 419 | .build_full_result() 420 | ] 421 | 422 | if user_inline_policies_results[0].get('PolicyNames'): 423 | inline_policies = user_inline_policies_results[0]['PolicyNames'] 424 | else: 425 | inline_policies = [] 426 | 427 | for inline_policy in inline_policies: 428 | 429 | policy = iam_client.get_user_policy( 430 | UserName=name, 431 | PolicyName=inline_policy 432 | ) 433 | 434 | policy_doc = policy['PolicyDocument'] 435 | 436 | str_policy = json.dumps(policy_doc, indent=None, separators=(',', ':')) 437 | 438 | #Strip white space 439 | stripped_str_policy = str_policy.replace(" ", "") 440 | char_count = len(stripped_str_policy) 441 | 442 | user_inline_policy_size += char_count 443 | 444 | usage = round(user_inline_policy_size / 2048, 4) 445 | char_left = 2048 - user_inline_policy_size 446 | 447 | if usage >= threshold: 448 | warning_users.append({ 449 | 'arn': arn, 450 | 'name': name, 451 | 'usage': usage, 452 | 'charleft': char_left 453 | }) 454 | 455 | except: 456 | print("Issue with listing inline policies for user: " + name) 457 | continue 458 | 459 | #Eventually standardize output here 460 | #Output Section 461 | print("IAM Users Scanned: " + str(len(users))) 462 | print(f"IAM Users with inline policy usage over {threshold:.2%} " + str(len(warning_users))) 463 | print('\n') 464 | 465 | if len(warning_users) > 0: 466 | print(f"List of users with more than {threshold:.2%} inline policy character usage: ") 467 | 468 | for user in warning_users: 469 | print(user['arn']) 470 | print(f"User Name: {user['name']}") 471 | print(f"Inline Policy Usage: {user['usage']:.2%}") 472 | print("Characters Left: " + str(user['charleft']) + '\n') 473 | 474 | save_output_to_file(warning_users) 475 | 476 | elif limit == "AWS IAM Group Inline Policies": 477 | try: 478 | session = boto3.Session(profile_name = args.profile) 479 | iam_client = session.client('iam') 480 | except: 481 | print("Potential authentication issue: check credentials and try again") 482 | sys.exit() 483 | 484 | try: 485 | iam_groups_results = [ 486 | iam_client.get_paginator('list_groups') 487 | .paginate() 488 | .build_full_result() 489 | ] 490 | except: 491 | print("Issue with listing IAM groups") 492 | sys.exit() 493 | 494 | groups = iam_groups_results[0]['Groups'] 495 | warning_groups = [] 496 | 497 | for group in groups: 498 | arn = group['Arn'] 499 | name = group['GroupName'] 500 | 501 | group_inline_policy_size = 0 502 | 503 | try: 504 | group_inline_policies_results = [ 505 | iam_client.get_paginator('list_group_policies') 506 | .paginate(GroupName=name) 507 | .build_full_result() 508 | ] 509 | 510 | if group_inline_policies_results[0].get('PolicyNames'): 511 | inline_policies = group_inline_policies_results[0]['PolicyNames'] 512 | else: 513 | inline_policies = [] 514 | 515 | for inline_policy in inline_policies: 516 | 517 | policy = iam_client.get_group_policy( 518 | GroupName=name, 519 | PolicyName=inline_policy 520 | ) 521 | 522 | policy_doc = policy['PolicyDocument'] 523 | 524 | str_policy = json.dumps(policy_doc, indent=None, separators=(',', ':')) 525 | 526 | #Strip white space 527 | stripped_str_policy = str_policy.replace(" ", "") 528 | char_count = len(stripped_str_policy) 529 | 530 | group_inline_policy_size += char_count 531 | 532 | usage = round(group_inline_policy_size / 5120, 4) 533 | char_left = 5120 - group_inline_policy_size 534 | 535 | if usage >= threshold: 536 | warning_groups.append({ 537 | 'arn': arn, 538 | 'name': name, 539 | 'usage': usage, 540 | 'charleft': char_left 541 | }) 542 | 543 | except: 544 | print("Issue with listing inline policies for group: " + name) 545 | continue 546 | #Eventually standardize output here 547 | #Output Section 548 | print("IAM Groups Scanned: " + str(len(groups))) 549 | print(f"IAM Groups with inline policy usage over {threshold:.2%} " + str(len(warning_groups))) 550 | print('\n') 551 | 552 | if len(warning_groups) > 0: 553 | print(f"List of groups with more than {threshold:.2%} inline policy character usage: ") 554 | 555 | for group in warning_groups: 556 | print(group['arn']) 557 | print(f"Group Name: {group['name']}") 558 | print(f"Inline Policy Usage: {group['usage']:.2%}") 559 | print("Characters Left: " + str(group['charleft']) + '\n') 560 | 561 | save_output_to_file(warning_groups) 562 | 563 | elif limit == "AWS EC2 User Data": 564 | try: 565 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 566 | ec2_client = session.client('ec2') 567 | except: 568 | print("Potential authentication issue: check credentials and try again") 569 | sys.exit() 570 | 571 | try: 572 | ec2_results = [ 573 | ec2_client.get_paginator('describe_instances') 574 | .paginate() 575 | .build_full_result() 576 | ] 577 | except: 578 | print("Issue with listing EC2 instances") 579 | sys.exit() 580 | 581 | instances = ec2_results[0]['Reservations'] 582 | 583 | warning_instances = [] 584 | 585 | for reservation in instances: 586 | for instance in reservation['Instances']: 587 | try: 588 | instance_id = instance['InstanceId'] 589 | user_data = ec2_client.describe_instance_attribute( 590 | InstanceId=instance_id, 591 | Attribute='userData' 592 | ) 593 | 594 | if user_data.get('UserData').get('Value'): 595 | user_data = user_data['UserData']['Value'] 596 | 597 | decoded_user_data_bytes = base64.b64decode(user_data) 598 | decoded_user_data = decoded_user_data_bytes.decode('utf-8') 599 | 600 | char_count = len(decoded_user_data) 601 | else: 602 | char_count = 0 603 | 604 | char_left = 16384 - char_count 605 | usage = round(char_count / 16384, 4) 606 | 607 | if usage >= threshold: 608 | warning_instances.append({ 609 | 'instance_id': instance_id, 610 | 'usage': usage, 611 | 'sizeleft': char_left 612 | }) 613 | 614 | except: 615 | print(f"Issue processing instance: {instance_id}") 616 | 617 | #Eventually standardize output here 618 | #Output Section 619 | print("EC2 Instances Scanned: " + str(len(instances))) 620 | print(f"EC2 Instances with usage over {threshold:.2%} " + str(len(warning_instances))) 621 | print('\n') 622 | 623 | if len(warning_instances) > 0: 624 | print(f"List of instances with more than {threshold:.2%} size usage: ") 625 | 626 | for instance in warning_instances: 627 | print(instance['instance_id']) 628 | print(f"Instance Usage: {instance['usage']:.2%}") 629 | print(f"Size Left: {instance['sizeleft']} Bytes \n") 630 | 631 | save_output_to_file(warning_instances) 632 | 633 | elif limit == "S3 Bucket Policy": 634 | try: 635 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 636 | s3_client = session.client('s3') 637 | except: 638 | print("Potential authentication issue: check credentials and try again") 639 | sys.exit() 640 | 641 | try: 642 | s3_buckets_results = [ 643 | s3_client.get_paginator('list_buckets') 644 | .paginate() 645 | .build_full_result() 646 | ] 647 | except: 648 | print("Issue with listing S3 buckets") 649 | sys.exit() 650 | 651 | buckets = s3_buckets_results[0]['Buckets'] 652 | warning_buckets = [] 653 | 654 | for bucket in buckets: 655 | bucket_name = bucket['Name'] 656 | 657 | try: 658 | bucket_policy = s3_client.get_bucket_policy(Bucket=bucket_name) 659 | policy_document = json.loads(bucket_policy['Policy']) 660 | 661 | str_policy = json.dumps(policy_document, indent=None, separators=(',', ':')) 662 | 663 | stripped_str_policy = str_policy.replace(" ", "") 664 | char_count = len(stripped_str_policy) 665 | 666 | # Approximate normalization for S3 bucket policy (0.8720 factor) 667 | usage = round(char_count / 20480 * 0.8720, 4) # 20 KB limit for S3 bucket policy 668 | char_left = 20480 - (usage * 20480) 669 | 670 | if usage >= threshold: 671 | warning_buckets.append({ 672 | 'bucket_name': bucket_name, 673 | 'usage': usage, 674 | 'charleft': char_left 675 | }) 676 | 677 | except Exception as e: 678 | if e.response["Error"]["Code"] == "NoSuchBucketPolicy": 679 | #print(f"No policy found for bucket: {bucket_name}") 680 | 681 | if 0 >= threshold: 682 | warning_buckets.append({ 683 | 'bucket_name': bucket_name, 684 | 'usage': 0, 685 | 'charleft': 20480 686 | }) 687 | 688 | else: 689 | print(f"Issue processing bucket: {bucket_name} - {str(e)}") 690 | 691 | print("S3 Buckets Scanned: " + str(len(buckets))) 692 | print(f"S3 Buckets with policy usage over {threshold:.2%} " + str(len(warning_buckets))) 693 | print('\n') 694 | 695 | if len(warning_buckets) > 0: 696 | print(f"List of buckets with more than {threshold:.2%} policy bytes usage: ") 697 | 698 | for bucket in warning_buckets: 699 | print(bucket['bucket_name']) 700 | print(f"Bucket Policy Usage: {bucket['usage']:.2%}") 701 | print("Bytes Left: " + str(bucket['charleft']) + '\n') 702 | 703 | save_output_to_file(warning_buckets) 704 | 705 | elif (limit == 'Organizations SCPs' or 706 | limit == 'Organizations RCPs' or 707 | limit == 'Organizations Declarative Policies' or 708 | limit == 'Organizations AI Services Opt-Out Policies' or 709 | limit == 'Organizations Tag Policies' or 710 | limit == 'Organizations Backup Policies' or 711 | limit == 'Organizations Chat Applications Policies' 712 | ): 713 | 714 | try: 715 | session = boto3.Session(profile_name = args.profile) 716 | organizations_client = session.client('organizations') 717 | except: 718 | print("Potential authentication issue: check credentials and try again") 719 | sys.exit() 720 | 721 | if limit == 'Organizations SCPs': 722 | selected_resource = "SCP" 723 | size_limit = 5120 724 | elif limit == 'Organizations RCPs': 725 | selected_resource = "RCP" 726 | size_limit = 5120 727 | elif limit == "Organizations Declarative Policies": 728 | selected_resource = "Declarative Policy" 729 | size_limit = 10000 730 | elif limit == "Organizations AI Services Opt-Out Policies": 731 | selected_resource = "AI Services Opt-Out Policy" 732 | size_limit = 2500 733 | elif limit == "Organizations Tag Policies": 734 | selected_resource = "Tag Policy" 735 | size_limit = 10000 736 | elif limit == "Organizations Backup Policies": 737 | selected_resource = "Backup Policy" 738 | size_limit = 10000 739 | elif limit == "Organizations Chat Applications Policies": 740 | selected_resource = "Chat Application Policy" 741 | size_limit = 10000 742 | 743 | try: 744 | 745 | if selected_resource == "SCP": 746 | org_filter = 'SERVICE_CONTROL_POLICY' 747 | elif selected_resource == "RCP": 748 | org_filter = 'RESOURCE_CONTROL_POLICY' 749 | elif selected_resource == "Declarative Policy": 750 | org_filter = 'DECLARATIVE_POLICY_EC2' 751 | elif selected_resource == "AI Services Opt-Out Policy": 752 | org_filter = 'AISERVICES_OPT_OUT_POLICY' 753 | elif selected_resource == "Tag Policy": 754 | org_filter = 'TAG_POLICY' 755 | elif selected_resource == "Backup Policy": 756 | org_filter = 'BACKUP_POLICY' 757 | elif selected_resource == "Chat Application Policy": 758 | org_filter = 'CHATBOT_POLICY' 759 | 760 | organizations_results = [ 761 | organizations_client.get_paginator('list_policies') 762 | .paginate( 763 | Filter=org_filter 764 | ) 765 | .build_full_result() 766 | ] 767 | except: 768 | print("Issue with listing " + selected_resource) 769 | sys.exit() 770 | 771 | org_policies = organizations_results[0]['Policies'] 772 | warning_org_policies = [] 773 | 774 | for policy in org_policies: 775 | try: 776 | policy_details = organizations_client.describe_policy( 777 | PolicyId=policy['Id'] 778 | ) 779 | 780 | policy_content = policy_details['Policy']['Content'] 781 | policy_id = policy['Id'] 782 | policy_name = policy['Name'] 783 | 784 | #Policy will automatically remove whitespace if saved via console. Whitespace is not removed if saved via CLI/API. 785 | char_count = len(policy_content) 786 | 787 | char_left = size_limit - char_count 788 | usage = round(char_count / size_limit, 4) 789 | 790 | if usage >= threshold: 791 | warning_org_policies.append({ 792 | 'policy_id': policy_id, 793 | 'policy_name': policy_name, 794 | 'usage': usage, 795 | 'charleft': char_left 796 | }) 797 | 798 | except: 799 | print(f"Issue processing {selected_resource}: {policy_id}") 800 | 801 | #Eventually standardize output here 802 | #Output Section 803 | print(f"Organizations {selected_resource} resources scanned: " + str(len(org_policies))) 804 | print(f"Organizations {selected_resource} resources with usage over {threshold:.2%} " + str(len(warning_org_policies))) 805 | print('\n') 806 | 807 | if len(warning_org_policies) > 0: 808 | print(f"{selected_resource} resources with more than {threshold:.2%} character usage: ") 809 | 810 | for policy in warning_org_policies: 811 | print(policy['policy_name']) 812 | print(f"{selected_resource} Usage: {policy['usage']:.2%}") 813 | 814 | print("Characters Left: " + str(policy['charleft']) + '\n') 815 | 816 | save_output_to_file(warning_org_policies) 817 | 818 | elif limit == 'SSM Parameter Store Parameters': 819 | try: 820 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 821 | ssm_client = session.client('ssm') 822 | except: 823 | print("Potential authentication issue: check credentials and try again") 824 | sys.exit() 825 | 826 | try: 827 | ssm_results = [ 828 | ssm_client.get_paginator('describe_parameters') 829 | .paginate() 830 | .build_full_result() 831 | ] 832 | except: 833 | print("Issue with listing SSM parameters") 834 | sys.exit() 835 | 836 | ssm_parameters = ssm_results[0]['Parameters'] 837 | warning_ssm_parameters = [] 838 | 839 | for parameter in ssm_parameters: 840 | try: 841 | parameter_name = parameter['Name'] 842 | parameter_tier = parameter['Tier'] 843 | parameter_arn = parameter['ARN'] 844 | 845 | parameter_value = ssm_client.get_parameter( 846 | Name=parameter_name, 847 | WithDecryption=True 848 | ) 849 | 850 | if parameter_tier == 'Standard': 851 | param_size = 4906 852 | elif parameter_tier == 'Advanced': 853 | param_size = 8192 854 | 855 | char_count = len(parameter_value['Parameter']['Value']) 856 | 857 | char_left = param_size - char_count 858 | usage = round(char_count / param_size, 4) 859 | 860 | if usage >= threshold: 861 | warning_ssm_parameters.append({ 862 | 'parameter_name': parameter_name, 863 | 'usage': usage, 864 | 'charleft': char_left 865 | }) 866 | 867 | except: 868 | print(f"Issue processing SSM parameter: {parameter_name}") 869 | 870 | #Eventually standardize output here 871 | #Output Section 872 | print("SSM Parameters Scanned: " + str(len(ssm_parameters))) 873 | print(f"SSM Parameters with usage over {threshold:.2%} " + str(len(warning_ssm_parameters))) 874 | print('\n') 875 | 876 | if len(warning_ssm_parameters) > 0: 877 | print(f"List of SSM parameters with more than {threshold:.2%} character usage: ") 878 | 879 | for parameter in warning_ssm_parameters: 880 | print(parameter['parameter_name']) 881 | print(f"Parameter Usage: {parameter['usage']:.2%}") 882 | print("Characters Left: " + str(parameter['charleft']) + '\n') 883 | 884 | save_output_to_file(warning_ssm_parameters) 885 | 886 | elif limit == 'Lambda Environment Variables': 887 | try: 888 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 889 | lambda_client = session.client('lambda') 890 | except: 891 | print("Potential authentication issue: check credentials and try again") 892 | sys.exit() 893 | 894 | try: 895 | lambda_results = [ 896 | lambda_client.get_paginator('list_functions') 897 | .paginate() 898 | .build_full_result() 899 | ] 900 | except: 901 | print("Issue with listing Lambda functions") 902 | sys.exit() 903 | 904 | lambda_functions = lambda_results[0]['Functions'] 905 | warning_lambda_functions = [] 906 | 907 | for function in lambda_functions: 908 | try: 909 | function_name = function['FunctionName'] 910 | function_arn = function['FunctionArn'] 911 | if function.get('Environment'): 912 | function_env = function.get('Environment') 913 | 914 | env_var_size = sum(len(key) + len(value) + 6 for key, value in function_env['Variables'].items()) 915 | #Add 5 characters per key value pair for quotes, comma, and colon 916 | 917 | char_left = 4096 - env_var_size 918 | usage = round(env_var_size / 4096, 4) 919 | 920 | else: 921 | # If no environment variables, consider it 0 usage 922 | char_left = 4096 923 | usage = 0 924 | 925 | if usage >= threshold: 926 | warning_lambda_functions.append({ 927 | 'function_name': function_name, 928 | 'usage': usage, 929 | 'charleft': char_left 930 | }) 931 | except: 932 | print(f"Issue processing Lambda function: {function_name}") 933 | 934 | #Eventually standardize output here 935 | #Output Section 936 | print("Lambda Functions Scanned: " + str(len(lambda_functions))) 937 | print(f"Lambda Functions with environment variable usage over {threshold:.2%} " + str(len(warning_lambda_functions))) 938 | print('\n') 939 | 940 | if len(warning_lambda_functions) > 0: 941 | print(f"List of Lambda functions with more than {threshold:.2%} environment variable size usage: ") 942 | 943 | for function in warning_lambda_functions: 944 | print(function['function_name']) 945 | print(f"Environment Variable Usage: {function['usage']:.2%}") 946 | print("Characters Left: " + str(function['charleft']) + '\n') 947 | 948 | save_output_to_file(warning_lambda_functions) 949 | 950 | elif limit == 'Secrets Manager Secrets': 951 | try: 952 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 953 | secretsmanager_client = session.client('secretsmanager') 954 | except: 955 | print("Potential authentication issue: check credentials and try again") 956 | sys.exit() 957 | 958 | try: 959 | secretsmanager_results = [ 960 | secretsmanager_client.get_paginator('list_secrets') 961 | .paginate() 962 | .build_full_result() 963 | ] 964 | except: 965 | print("Issue with listing Secrets Manager secrets") 966 | sys.exit() 967 | 968 | secretsmanager_secrets = secretsmanager_results[0]['SecretList'] 969 | warning_secretsmanager_secrets = [] 970 | 971 | for secret in secretsmanager_secrets: 972 | try: 973 | secret_name = secret['Name'] 974 | secret_arn = secret['ARN'] 975 | 976 | secret_value = secretsmanager_client.get_secret_value( 977 | SecretId=secret_arn 978 | ) 979 | 980 | secret_size = len(secret_value['SecretString']) 981 | 982 | char_left = 65536 - secret_size 983 | usage = round(secret_size / 65536, 4) 984 | 985 | if usage >= threshold: 986 | warning_secretsmanager_secrets.append({ 987 | 'secret_name': secret_name, 988 | 'usage': usage, 989 | 'charleft': char_left 990 | }) 991 | 992 | except: 993 | print(f"Issue processing Secrets Manager secret: {secret_name}") 994 | 995 | #Eventually standardize output here 996 | #Output Section 997 | print("Secrets Manager Secrets Scanned: " + str(len(secretsmanager_secrets))) 998 | print(f"Secrets Manager Secrets with usage over {threshold:.2%} " + str(len(warning_secretsmanager_secrets))) 999 | print('\n') 1000 | 1001 | if len(warning_secretsmanager_secrets) > 0: 1002 | print(f"List of Secrets Manager secrets with more than {threshold:.2%} character usage: ") 1003 | 1004 | for secret in warning_secretsmanager_secrets: 1005 | print(secret['secret_name']) 1006 | print(f"Secret Usage: {secret['usage']:.2%}") 1007 | print("Characters Left: " + str(secret['charleft']) + '\n') 1008 | 1009 | save_output_to_file(warning_secretsmanager_secrets) 1010 | 1011 | elif limit == 'VPC Endpoint Policies': 1012 | try: 1013 | session = boto3.Session(profile_name = args.profile, region_name = args.region) 1014 | ec2_client = session.client('ec2') 1015 | except: 1016 | print("Potential authentication issue: check credentials and try again") 1017 | sys.exit() 1018 | 1019 | try: 1020 | interface_endpoints_results = [ 1021 | ec2_client.get_paginator('describe_vpc_endpoints') 1022 | .paginate( 1023 | Filters=[ 1024 | { 1025 | 'Name': 'vpc-endpoint-type', 1026 | 'Values': ['Interface'] 1027 | } 1028 | ] 1029 | ) 1030 | .build_full_result() 1031 | ] 1032 | 1033 | interface_vpc_endpoints = interface_endpoints_results[0]['VpcEndpoints'] 1034 | 1035 | warning_vpc_endpoints = [] 1036 | 1037 | for endpoint in interface_vpc_endpoints: 1038 | try: 1039 | endpoint_id = endpoint['VpcEndpointId'] 1040 | 1041 | if endpoint.get('ServiceName'): 1042 | endpoint_service = endpoint['ServiceName'] 1043 | else: 1044 | endpoint_service = "N/A" 1045 | 1046 | if endpoint.get('PolicyDocument'): 1047 | policy_document = endpoint['PolicyDocument'] 1048 | 1049 | char_count = len(policy_document) 1050 | 1051 | char_left = 20480 - char_count 1052 | usage = round(char_count / 20480, 4) 1053 | 1054 | if usage >= threshold: 1055 | warning_vpc_endpoints.append({ 1056 | 'endpoint_id': endpoint_id, 1057 | 'endpoint_service': endpoint_service, 1058 | 'usage': usage, 1059 | 'charleft': char_left 1060 | }) 1061 | else: 1062 | # If no policy document, consider it 0 usage 1063 | if 0 >= threshold: 1064 | warning_vpc_endpoints.append({ 1065 | 'endpoint_id': endpoint_id, 1066 | 'endpoint_service': endpoint_service, 1067 | 'usage': 0, 1068 | 'charleft': 20480 1069 | }) 1070 | 1071 | except: 1072 | print(f"Issue processing VPC Endpoint: {endpoint_id}") 1073 | 1074 | print("Interface VPC Endpoints Scanned: " + str(len(interface_vpc_endpoints))) 1075 | print(f"Interface VPC Endpoints with policy usage over {threshold:.2%} " + str(len(warning_vpc_endpoints))) 1076 | print('\n') 1077 | 1078 | if len(warning_vpc_endpoints) > 0: 1079 | print(f"List of Interface VPC Endpoints with more than {threshold:.2%} policy character usage: ") 1080 | 1081 | for endpoint in warning_vpc_endpoints: 1082 | print(endpoint['endpoint_id']) 1083 | print(f"Service Name: {endpoint['endpoint_service']}") 1084 | print(f"Policy Usage: {endpoint['usage']:.2%}") 1085 | print("Characters Left: " + str(endpoint['charleft']) + '\n') 1086 | 1087 | save_output_to_file(warning_vpc_endpoints) 1088 | 1089 | except: 1090 | print("Issue with listing Interface VPC Endpoints") 1091 | sys.exit() --------------------------------------------------------------------------------