Last active
April 14, 2021 11:25
-
-
Save cardil/a032b5021ae31bcd616c834fd1e39e82 to your computer and use it in GitHub Desktop.
A littple script that fetches VPC releated AWS quotas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def regions = ["us-west-1", "us-west-2", "us-east-1", "us-east-2", "eu-west-1"] | |
def vpcService = 'vpc' | |
def vpcCode = 'L-F678F1CE' | |
def natCode = 'L-FE5A380F' | |
def elasticIpService = 'ec2' | |
def elasticIpCode = 'L-0263D0A3' | |
println "Current AWS limits" | |
println "------------------" | |
println "" | |
println "Region: \t VPCs \t NAT Gateways \t VPC Elastic IPs" | |
regions.each { region -> | |
vpcLimit = getLimit(region, vpcService, vpcCode) | |
elasticIdLimit = getLimit(region, elasticIpService, elasticIpCode) | |
natGatewaysLimit = getLimit(region, vpcService, natCode) | |
println "${region} \t ${vpcLimit} \t ${natGatewaysLimit} \t\t ${elasticIdLimit}" | |
} | |
BigDecimal getLimit(String region, String service, String code) { | |
def command = "aws --region ${region} service-quotas get-service-quota --service-code ${service} --quota-code ${code} --output json" | |
proc = command.execute() | |
def json = proc.text | |
def slurper = new JsonSlurper() | |
def result = slurper.parseText(json) | |
return result.Quota.Value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment