user3645914
user3645914

Reputation: 51

AWS Service Quota: How to get service quota for Amazon S3 using boto3

I get the error "An error occurred (NoSuchResourceException) when calling the GetServiceQuota operation:" while trying running the following boto3 python code to get the value of quota for "Buckets"

client_quota = boto3.client('service-quotas')
resp_s3 = client_quota.get_service_quota(ServiceCode='s3', QuotaCode='L-89BABEE8')

In the above code, QuotaCode "L-89BABEE8" is for "Buckets". I presumed the value of ServiceCode for Amazon S3 would be "s3" so I put it there but I guess that is wrong and throwing error. I tried finding the documentation around ServiceCode for S3 but could not find it. I even tried with "S3" (uppercase 'S' here), "Amazon S3" but that didn't work as well.

What I tried? client_quota = boto3.client('service-quotas') resp_s3 = client_quota.get_service_quota(ServiceCode='s3', QuotaCode='L-89BABEE8')

What I expected? Output in the below format for S3. Below example is for EC2 which is the output of resp_ec2 = client_quota.get_service_quota(ServiceCode='ec2', QuotaCode='L-6DA43717')

Upvotes: 2

Views: 1340

Answers (2)

Ethan
Ethan

Reputation: 121

As of today 10 July 2024, this does NOT work.

Fetching S3 service quotas using the GetServiceQuota API is not supported.

https://repost.aws/questions/QUihn3DDUATCWh5NsMMqRQMw/i-am-not-able-to-fetch-service-quota-for-s3-at-account-level#ANYS7lKWawRnKt2Ff7z5jGmw

Upvotes: 0

Mark B
Mark B

Reputation: 200988

I just played around with this and I'm seeing the same thing you are, empty responses from any service quota list or get command for service s3. However s3 is definitely the correct service code, because you see that come back from the service quota list_services() call. Then I saw there are also list and get commands for AWS default service quotas, and when I tried that it came back with data. I'm not entirely sure, but based on the docs I think any quota that can't be adjusted, and possibly any quota your account hasn't requested an adjustment for, will probably come back with an empty response from get_service_quota() and you'll need to run get_aws_default_service_quota() instead.

So I believe what you need to do is probably run this first:

client_quota.get_service_quota(ServiceCode='s3', QuotaCode='L-89BABEE8')

And if that throws an exception, then run the following:

client_quota.get_aws_default_service_quota(ServiceCode='s3', QuotaCode='L-89BABEE8')

Upvotes: 2

Related Questions