cost explorer in python-boto3 unknown service 'ce'

Viewed 2426

Good day, Recent AWS release API for know the billing information.

It is available in all aws SDK (c#,python,php). I just tried a lambda function to update my database table with current cost of my all linked accounts. but mt lambda function doesn't work. it show the following error

"Unknown service: 'ce'. Valid service names are: acm, apigateway, application-autoscaling, appstream, athena, autoscaling,etc "

my lambda code is :

import boto3
from datetime import datetime, timedelta
def lambda_handler(event, context):
client1 = boto3.client(
'ce',
aws_access_key_id=accesskey,
aws_secret_access_key=secretkey)
[referral link for client creation][1]
response = client1.get_cost_and_usage(
TimePeriod={
    'Start': startdate,
    'End': enddate
},
Granularity='MONTHLY',
Metrics=[
    'BlendedCost',
],
GroupBy=[
    {
        'Type': 'DIMENSION',
        'Key': 'LINKED_ACCOUNT'
    },
],
)

print response
3 Answers

As mentioned in the Boto3 bugtracker this might happen if you have updated your boto3 without updating your botocore.

So I suggest to update botocore and retry:

pip install botocore --upgrade

or in some different way, depends on how you installed botocore in the first place.

I think simply AWS Lambda team hasn't upgraded botocore to the newest version yet. As the moment of writing this, the docs for AWS Lambda mention 1.7.37 as current version of botocore:

AWS SDK for Python 2.7 (Boto 3) version 3-1.4.7 botocore-1.7.37

AWS SDK for Python 3.6 (Boto 3) version 3-1.4.7 botocore-1.7.37

And reading the botocore changelog the oldest it mentions ce is 1.7.48:

1.7.48

[...]

api-change:ce: Update ce client to latest version

So my guess is - one AWS team hasn't picked up what some other team at AWS already had released.

You can contact AWS support or wait a few days. I'd guess.

Related