Skip to content

Instantly share code, notes, and snippets.

@cardil
Last active April 14, 2021 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardil/a032b5021ae31bcd616c834fd1e39e82 to your computer and use it in GitHub Desktop.
Save cardil/a032b5021ae31bcd616c834fd1e39e82 to your computer and use it in GitHub Desktop.
A littple script that fetches VPC releated AWS quotas
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