Type annotations for boto3 BillingandCostManagementPricingCalculator

1.42.3 · active · verified Sat Apr 11

Provides type annotations for the `boto3` AWS Billing and Cost Management Pricing Calculator service. It enhances static type checking for `boto3` clients, resources, and their methods, offering improved autocomplete and error detection in IDEs and with tools like `mypy` and `pyright`. This package is part of the `mypy-boto3-builder` ecosystem, which typically releases updates in sync with `boto3` versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `bcm-pricing-calculator` client with `boto3` and leverage the provided type hints. It includes an example of creating a bill scenario and listing existing ones. Ensure your AWS credentials are configured for authentication.

import boto3
from mypy_boto3_bcm_pricing_calculator.client import BillingandCostManagementPricingCalculatorClient
from typing import TYPE_CHECKING, cast
import os

# Ensure AWS credentials are configured (e.g., via environment variables, ~/.aws/credentials)
# For a runnable example, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION are set.
# Or configure a mock client for testing without actual AWS calls.

if TYPE_CHECKING:
    client: BillingandCostManagementPricingCalculatorClient = boto3.client("bcm-pricing-calculator")
else:
    client = boto3.client("bcm-pricing-calculator")

try:
    # Example: Create a new bill scenario
    # The Billing and Cost Management Pricing Calculator API is complex and often requires specific parameters.
    # This is a minimal example; adjust parameters as per your actual use case.
    scenario_name = f"MyTypeHintedScenario-{os.urandom(4).hex()}"
    response = client.create_bill_scenario(
        Name=scenario_name,
        GroupSharingPreference='OPEN'
    )
    print(f"Successfully created bill scenario: {response['name']} (ID: {response['id']})")

    # Example of retrieving scenarios (if any exist)
    list_response = client.list_bill_scenarios()
    print("\nExisting Bill Scenarios:")
    for scenario in list_response.get('BillScenarios', []):
        print(f"  - {scenario['name']} (ID: {scenario['id']})")

    # For cleanup, you might delete the created scenario:
    # client.delete_bill_scenario(Id=response['id'])
    # print(f"Deleted scenario {response['id']}")

except client.exceptions.AccessDeniedException:
    print("Access Denied. Ensure your AWS credentials have permissions for bcm-pricing-calculator service.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →