Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ out/
__pycache__
*.pyc

# Python virtual environment
.venv

# Go best practices dictate that libraries should not include the vendor directory
vendor
Expand Down
41 changes: 41 additions & 0 deletions codegen/quotas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# AWS Service Quotas Generator

This Python script generates a markdown document containing a comprehensive list of all adjustable AWS service quotas. The document includes the service name, service code, quota code, quota name and quota value. This tool is designed to help users easily track service quotas for better resource management and planning.

Note that generating the quotas could be time consuming as the script honors the API limits for the used AWS APIs.

## Requirements
- Python 3.6+
- Boto3
- AWS CLI (optional, for configuring AWS credentials)

## Usage

Ensure you have valid AWS credentials to access the service quotas service.

### Install Dependencies
Install the required Python packages by running:

```
pip install -r requirements.txt
```

### Command Line Arguments
The script accepts the following command line arguments:

- `--region` (optional): Specify the AWS region to query service quotas for. Defaults to `us-east-1`.
- `--output` (optional): Specify the output markdown file path for the quotas. Defaults to `../../docs/quotas.md`.

### Running the Script
To run the script with default settings (region `us-east-1` and output `../../docs/quotas.md`):

```
python generate_quotas.py
```

To specify a different region and output file:

```
python generate_quotas.py --region us-west-2 --output "./path/to/your/output.md"

```
85 changes: 85 additions & 0 deletions codegen/quotas/generate_quotas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import argparse
import os
import time

import boto3

# Parse command-line arguments
parser = argparse.ArgumentParser(
description="Generate a markdown document of all adjustable AWS service quotas."
)
parser.add_argument(
"--region",
default="us-east-1",
help="AWS region to query service quotas for. Defaults to us-east-1.",
)
parser.add_argument(
"--output",
default="../../docs/quotas.md",
help='Output markdown file for the quotas. Defaults to "../../docs/quotas.md".',
)
args = parser.parse_args()

# Initialize a boto3 client for Service Quotas in the specified region
client = boto3.client("service-quotas", region_name=args.region)


def list_all_services():
"""List all AWS services that have quotas."""
services = []
response = client.list_services()
services.extend(response["Services"])
while "NextToken" in response:
time.sleep(0.3) # Delay to respect rate limits
response = client.list_services(NextToken=response["NextToken"])
services.extend(response["Services"])
return services


def list_quotas_for_service(service_code):
"""List the quotas for a given service by its service code."""
print(f"Fetching quotas for service {service_code}")
quotas = []
response = client.list_aws_default_service_quotas(ServiceCode=service_code)
quotas.extend(response["Quotas"])
while "NextToken" in response:
time.sleep(0.3) # Delay to respect rate limits
response = client.list_aws_default_service_quotas(
ServiceCode=service_code, NextToken=response["NextToken"]
)
quotas.extend(response["Quotas"])
return quotas


def generate_markdown_document(services):
"""Generate a markdown document for the given services and their quotas."""
markdown = "## Adjustable AWS Service Quotas\n\n"
markdown += "| Service Name | Service Code | Quota Name | Quota Code | Default |\n"
markdown += "| ------------ | ------------ | ---------- | ---------- | ------- |\n"
for service in services:
time.sleep(
0.3
) # Adjust this based on your rate limit analysis and AWS documentation
quotas = list_quotas_for_service(service["ServiceCode"])
for quota in quotas:
if quota["Adjustable"]:
markdown += f"| {service['ServiceName']} | {service['ServiceCode']} | {quota['QuotaName']} | {quota['QuotaCode']} | {quota['Value']} |\n"
return markdown


# Fetch all services
services = list_all_services()

# Generate the markdown document
markdown_document = generate_markdown_document(services)

# Ensure the output directory exists
output_dir = os.path.dirname(args.output)
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Write the markdown document to the specified output file
with open(args.output, "w") as file:
file.write(markdown_document)

print(f"Quota information has been written to {args.output}")
1 change: 1 addition & 0 deletions codegen/quotas/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3>=1.20.0,<2.0
Loading