def get_account_id(role_arn):
    """
    Returns the account ID for a given role ARN.
    """
    # The format of an IAM role ARN is
    #
    #     arn:partition:service:region:account:resource
    #
    # Where:
    #
    # - 'arn' is a literal string
    # - 'service' is always 'iam' for IAM resources
    # - 'region' is always blank for IAM resources
    # - 'account' is the AWS account ID with no hyphens
    #
    # See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns
    try:
        arn, _, service, region, account, _ = role_arn.split(":")
    except ValueError:
        raise ValueError(f"Is this a valid AWS ARN? {role_arn}")

    if arn != "arn":
        raise ValueError(f"Is this a valid AWS ARN? {role_arn}")

    if service != "iam" or region != "" or not account.isnumeric():
        raise ValueError(f"Is this an IAM role ARN? {role_arn}")

    return account