Skip to content

Conversation

andy-townsend
Copy link

Issue #, if available:

Current script defaults to scanning 17 regions which for us fails due to IAM permissions. We noticed it only got as far as 12 regions and then quit so this PR adds a --region flag to allow scanning of a single region.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

parser = argparse.ArgumentParser(description="Collect DynamoDB metrics")
parser.add_argument("--start-time", type=str, help="Start time in ISO8601 format")
parser.add_argument("--end-time", type=str, help="End time in ISO8601 format")
parser.add_argument(
Copy link
Contributor

@tebanieo tebanieo Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create first a constant that includes all the regions.

AWS_REGIONS = [
    "us-east-1", "us-east-2", "us-west-1", "us-west-2",
    "ca-central-1", "eu-west-1", "eu-west-2", "eu-west-3", 
    "eu-central-1", "eu-north-1", "eu-south-1", "ap-south-1",
    "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", 
    "ap-southeast-1", "ap-southeast-2", "ap-southeast-3",
    "sa-east-1", "me-south-1", "af-south-1"
]

Create a validation function

def is_valid_aws_region(region):
    return region in AWS_REGIONS

def validate_aws_region(region):
    if not is_valid_aws_region(region):
        raise argparse.ArgumentTypeError(f"Invalid AWS region: {region}")
    return region

And then add this to the arg parsing.

parser.add_argument('--region', '-r', required=False,
                        type=validate_aws_region,
                        help='AWS region to use')

Copy link
Contributor

@tebanieo tebanieo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, could you add the small change I requested? this will save errors before calling the AWS SDK.

@tebanieo tebanieo self-assigned this Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants