Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cost Explorer returns incorrect value for EDP #4115

Closed
Manoj-Paramsetti opened this issue May 5, 2024 · 4 comments
Closed

Cost Explorer returns incorrect value for EDP #4115

Manoj-Paramsetti opened this issue May 5, 2024 · 4 comments
Assignees
Labels
bug This issue is a confirmed bug. costexplorer A low-level client representing AWS Cost Explorer Service response-requested Waiting on additional information or feedback. service-api This issue is caused by the service API, not the SDK implementation.

Comments

@Manoj-Paramsetti
Copy link

Describe the bug

I'm endeavoring to retrieve the sum I received from EDP through boto3, yet consistently getting 0 USD across all my associated accounts. Despite attempting to filter out with the RECORD_TYPE parameter, the problem persists. However, I can discern the variance from the Cost Explorer page.

Below, I've included the code snippet I used along with the corresponding output, in an attempt to visualize the EDP amount.

Expected Behavior

Use case 1: I want to see the amount I got under Enterprise Discount Program.
Use case 2: Exclude EDP record type from linked accounts.

Current Behavior

Current Behavior in Use Case 1: Despite expecting a non-zero value, I consistently receive zero as the amount.
Current Behavior I Encounter in Use Case 2: Even after attempting to exclude or include EDP, there's no discernible difference.

Reproduction Steps

List Record Types for all Linked Account

client = session.client('ce')
response = client.get_cost_and_usage(
    TimePeriod={
        'Start': '2024-04-01',
        'End':  '2024-04-30',
    },
    Granularity='MONTHLY',
    Metrics=[
        'NetUnblendedCost'
    ],

    GroupBy=[
        {
            'Type': 'DIMENSION',
            'Key': "RECORD_TYPE"
        },
        {
            'Type': 'DIMENSION',
            'Key': "LINKED_ACCOUNT"
        }
    ]
)

Exlcude EDP

client = session.client('ce')
response = client.get_cost_and_usage(
    TimePeriod={
        'Start': '2024-03-01',
        'End':  '2024-03-31',
    },
    Granularity='MONTHLY',
    Metrics=[
        'NetUnblendedCost'
    ],
    Filter={
        "Not":
        {
            'Dimensions':{
            'Key': 'RECORD_TYPE',
            'Values':['Enterprise Discount Program Discount']
             }
        }
    },
    GroupBy=[
        {
            'Type': 'DIMENSION',
            'Key': "LINKED_ACCOUNT"
        }
    ]
)

Possible Solution

It appears that negative values are being assigned to 0.

Additional Information/Context

No response

SDK version used

boto3-1.34.98

Environment details (OS name and version, etc.)

Google Colab

@Manoj-Paramsetti Manoj-Paramsetti added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels May 5, 2024
@tim-finnigan tim-finnigan self-assigned this May 6, 2024
@tim-finnigan tim-finnigan added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label May 6, 2024
@tim-finnigan
Copy link
Contributor

Hi @Manoj-Paramsetti thanks for reaching out. The get_cost_and_usage command involves a call to the underlying GetCostAndUsage API. Therefore it sounds like this issue relates to the Cost Explorer service API rather than the Boto3 SDK directly. But we can try to investigate this issue and escalate it to the Cost Explorer team if necessary.

I was able to run both of your code snippets successfully, and received a NetUnblendedCost Amount above 0. Are you seeing different results in the AWS Console? Can you confirm that you're using the correct account/region when running your Boto3 script?

I'll also link this Cost Explorer guide for reference in case it is helpful. For further investigation on the SDK side you can get debug logs by adding boto3.set_stream_logger('') to your script, and redact any sensitive info.

@tim-finnigan tim-finnigan added response-requested Waiting on additional information or feedback. service-api This issue is caused by the service API, not the SDK implementation. costexplorer A low-level client representing AWS Cost Explorer Service and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels May 6, 2024
@Manoj-Paramsetti
Copy link
Author

@tim-finnigan , I'm using an admin's account credentials for my management account, so I believe there is no issue with the account. Since billing is a global service, the region won't be an issue. From the debugger, it shows that aws-global is selected. As you mentioned, the issue may be from the AWS CE API because the issue I face is from the API response.

DEBUG:botocore.regions:Calling endpoint provider with parameters: {'Region': 'aws-global', 'UseDualStack': False, 'UseFIPS': False}

In some keys, the NetUnblendedCost is above 0, but for us, we have an Enterprise Discount Program discount, which will result in a negative value in my billing. I can see $X amount under Recurring, Usage, and some record types, but for the EDP, it is zero.
Are you seeing different results in the AWS Console?
Yes, I see a different value if I include EDP in my AWS Console, and the EDP value is -$X.

@Manoj-Paramsetti
Copy link
Author

@tim-finnigan I've experimented with the metrics using UNBLENDED_COST, and now I can see the EDP amount. Thanks for your support @tim-finnigan .

Copy link

github-actions bot commented May 8, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. costexplorer A low-level client representing AWS Cost Explorer Service response-requested Waiting on additional information or feedback. service-api This issue is caused by the service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants