Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active January 17, 2026 20:01
Show Gist options
  • Select an option

  • Save jayers99/8d51cf2dc38eb3152bb06acf79ef0256 to your computer and use it in GitHub Desktop.

Select an option

Save jayers99/8d51cf2dc38eb3152bb06acf79ef0256 to your computer and use it in GitHub Desktop.
Scans codebase for AWS Backup API calls and lists unique calls with counts
# find_aws_api_calls.ps1
# Scans codebase for AWS Backup API calls and lists unique calls with counts
param(
[Parameter(Mandatory=$false)]
[string]$Path = ".",
[Parameter(Mandatory=$false)]
[string]$FilePattern = "*.py",
[Parameter(Mandatory=$false)]
[string]$OutputFile = ""
)
Write-Host "Scanning for AWS Backup API calls in: $Path" -ForegroundColor Cyan
Write-Host "File pattern: $FilePattern" -ForegroundColor Cyan
Write-Host ""
# Known AWS Backup API methods (from boto3/AWS docs)
$awsBackupMethods = @(
'create_backup_plan',
'create_backup_selection',
'create_backup_vault',
'create_framework',
'create_legal_hold',
'create_logically_air_gapped_backup_vault',
'create_report_plan',
'create_restore_testing_plan',
'create_restore_testing_selection',
'delete_backup_plan',
'delete_backup_selection',
'delete_backup_vault',
'delete_backup_vault_access_policy',
'delete_backup_vault_lock_configuration',
'delete_backup_vault_notifications',
'delete_framework',
'delete_recovery_point',
'delete_report_plan',
'delete_restore_testing_plan',
'delete_restore_testing_selection',
'describe_backup_job',
'describe_backup_vault',
'describe_copy_job',
'describe_framework',
'describe_global_settings',
'describe_protected_resource',
'describe_recovery_point',
'describe_region_settings',
'describe_report_job',
'describe_report_plan',
'describe_restore_job',
'disassociate_recovery_point',
'disassociate_recovery_point_from_parent',
'export_backup_plan_template',
'get_backup_plan',
'get_backup_plan_from_json',
'get_backup_plan_from_template',
'get_backup_selection',
'get_backup_vault_access_policy',
'get_backup_vault_notifications',
'get_legal_hold',
'get_recovery_point_restore_metadata',
'get_restore_job_metadata',
'get_restore_testing_inferred_metadata',
'get_restore_testing_plan',
'get_restore_testing_selection',
'get_supported_resource_types',
'list_backup_job_summaries',
'list_backup_jobs',
'list_backup_plan_templates',
'list_backup_plan_versions',
'list_backup_plans',
'list_backup_selections',
'list_backup_vaults',
'list_copy_job_summaries',
'list_copy_jobs',
'list_frameworks',
'list_legal_holds',
'list_protected_resources',
'list_protected_resources_by_backup_vault',
'list_recovery_points_by_backup_vault',
'list_recovery_points_by_legal_hold',
'list_recovery_points_by_parent',
'list_recovery_points_by_resource',
'list_report_jobs',
'list_report_plans',
'list_restore_job_summaries',
'list_restore_jobs',
'list_restore_jobs_by_protected_resource',
'list_restore_testing_plans',
'list_restore_testing_selections',
'list_tags',
'put_backup_vault_access_policy',
'put_backup_vault_lock_configuration',
'put_backup_vault_notifications',
'put_restore_validation_result',
'start_backup_job',
'start_copy_job',
'start_report_job',
'start_restore_job',
'stop_backup_job',
'tag_resource',
'untag_resource',
'update_backup_plan',
'update_framework',
'update_global_settings',
'update_recovery_point_lifecycle',
'update_region_settings',
'update_report_plan',
'update_restore_testing_plan',
'update_restore_testing_selection'
)
# Build regex pattern from method list
$methodPattern = ($awsBackupMethods | ForEach-Object { [regex]::Escape($_) }) -join '|'
$pattern = "\.($methodPattern)\s*\("
$results = Get-ChildItem -Path $Path -Filter $FilePattern -Recurse -File |
ForEach-Object {
$file = $_
Select-String -Path $file.FullName -Pattern $pattern -AllMatches |
ForEach-Object {
$line = $_
$line.Matches | ForEach-Object {
# Extract just the method name
$method = $_.Groups[1].Value
[PSCustomObject]@{
Method = $method
File = $file.Name
FullPath = $file.FullName
LineNumber = $line.LineNumber
LineText = $line.Line.Trim()
}
}
}
}
if ($results) {
Write-Host "=== API Calls by Frequency ===" -ForegroundColor Green
Write-Host ""
$summary = $results |
Group-Object -Property Method |
Select-Object @{N='API_Call';E={$_.Name}}, @{N='Count';E={$_.Count}} |
Sort-Object -Property Count -Descending
$summary | Format-Table -AutoSize
Write-Host ""
Write-Host "=== Total ===" -ForegroundColor Green
Write-Host "Unique API calls: $($summary.Count)"
Write-Host "Total occurrences: $($results.Count)"
if ($OutputFile) {
$summary | Export-Csv -Path $OutputFile -NoTypeInformation
Write-Host ""
Write-Host "Results exported to: $OutputFile" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "=== Details ===" -ForegroundColor Green
Write-Host ""
$results |
Group-Object -Property Method |
Sort-Object -Property Count -Descending |
ForEach-Object {
Write-Host "$($_.Name) ($($_.Count) occurrences):" -ForegroundColor Cyan
$_.Group | ForEach-Object {
Write-Host " $($_.File):$($_.LineNumber)" -ForegroundColor Gray
Write-Host " $($_.LineText)" -ForegroundColor DarkGray
}
Write-Host ""
}
} else {
Write-Host "No AWS Backup API calls found." -ForegroundColor Yellow
Write-Host ""
Write-Host "Searched for these methods:" -ForegroundColor Gray
$awsBackupMethods | ForEach-Object { Write-Host " $_" -ForegroundColor DarkGray }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment