How to get quotas of AWS via boto3?

Question:

I’m working on boto3 – SDK python for AWS.

I am starting with simple service quota for ec2 but always ending up with the below error,

import boto3

quota_client = boto3.client('service-quotas')
response = quota_client.get_service_quota(
ServiceCode='ec2'
)

Error:

botocore.exceptions.UnknownServiceError: Unknown service: 'service- 
quotas'. Valid service names are: acm, acm-pca, alexaforbusiness, 
amplify, apigateway, apigatewaymanagementapi, apigatewayv2, 
application-autoscaling, appmesh, appstream, appsync, athena, 
autoscaling, autoscaling-plans, backup, batch, budgets, ce, chime, 
cloud9, clouddirectory, cloudformation, cloudfront, cloudhsm, 
cloudhsmv2, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, 
codebuild, codecommit, codedeploy, codepipeline, codestar, cognito- 
identity, cognito-idp, cognito-sync, comprehend, comprehendmedical, 
config, connect, cur, datapipeline, datasync, dax, devicefarm, 
directconnect, discovery, dlm, dms, docdb, ds, dynamodb, 
dynamodbstreams, ec2, ecr, ecs, efs, eks, elasticache, 
elasticbeanstalk, elastictranscoder, elb, elbv2, emr, es, events, 
firehose, fms, fsx, gamelift, glacier, globalaccelerator, glue, 
greengrass, groundstation, guardduty, health, iam, importexport, 
inspector, iot, iot-data, iot-jobs-data, iot1click-devices, iot1click- 
projects, iotanalytics, iotevents, iotevents-data, iotthingsgraph, 
kafka, kinesis, kinesis-video-archived-media, kinesis-video-media, 
 kinesisanalytics, kinesisanalyticsv2, kinesisvideo, kms, lambda, lex- 
models, lex-runtime, license-manager, lightsail, logs, 
 machinelearning, macie, managedblockchain, marketplace-entitlement, 
 marketplacecommerceanalytics, mediaconnect, mediaconvert, medialive, 
 mediapackage, mediapackage-vod, mediastore, mediastore-data, 
mediatailor, meteringmarketplace, mgh, mobile, mq, mturk, neptune, 
 opsworks, opsworkscm, organizations, personalize, personalize-events, 
 personalize-runtime, pi, pinpoint, pinpoint-email, pinpoint-sms-voice, polly, pricing, 
 quicksight, ram, rds, rds-data, redshift, rekognition, resource-groups, 
 resourcegroupstaggingapi, robomaker, route53, route53domains, 
 route53resolver, s3, s3control, sagemaker, sagemaker-runtime, sdb, 
secretsmanager, securityhub, serverlessrepo, servicecatalog, 
servicediscovery, ses, shield, signer, sms, sms-voice, snowball, sns, sqs, 
ssm, stepfunctions, storagegateway, sts, support, swf, textract, 
transcribe, transfer, translate, waf, waf-regional, workdocs, worklink, 
workmail, workspaces, xray

The documentation page shows that service-quotas supported in boto3 but looks like it’s not or am I doing anything incorrect here?

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/service-quotas.html

Asked By: SimbuStar

||

Answers:

I could reproduce the problem with my current boto3-1.9.174 botocore-1.12.174 installation.

I then did:

pip install boto3 --upgrade

It moved me to version boto3-1.9.208 botocore-1.12.208 and it works fine.

I try to use Python virtual environments to isolate libraries for easy updating.

Answered By: John Rotenstein

Actually, get_service_quota() api expects the following two arguments
ServiceCode
QuotaCode

For e.g. For EC2, ServiceCode is "ec2" and QuotaCode will be the parameter that you want to check for e.g. if you want to check "Attachments per VPC", you need to specify it’s corresponding code "L-6DA43717". Those codes can be found at Service Quota page in the AWS console.

Answered By: user3645914