Complete the code to start a Cost Explorer query for daily costs.
response = client.get_cost_and_usage(TimePeriod={'Start': '2023-01-01', 'End': '2023-01-31'}, Granularity='[1]', Metrics=['UnblendedCost'])The Granularity parameter controls the time interval for the cost data. 'DAILY' returns daily cost data.
Complete the code to filter the Cost Explorer query by service name 'Amazon EC2'.
response = client.get_cost_and_usage(TimePeriod={'Start': '2023-01-01', 'End': '2023-01-31'}, Granularity='DAILY', Metrics=['UnblendedCost'], Filter={'Dimensions': {'Key': 'SERVICE', 'Values': [[1]]}})The filter uses the service name to limit results. Here, 'Amazon EC2' filters costs for EC2 only.
Fix the error in the code to correctly request cost data grouped by linked account.
response = client.get_cost_and_usage(TimePeriod={'Start': '2023-02-01', 'End': '2023-02-28'}, Granularity='MONTHLY', Metrics=['UnblendedCost'], GroupBy=[{'Type': 'DIMENSION', 'Key': [1]])To group costs by linked account, the GroupBy key must be 'LINKED_ACCOUNT'.
Fill both blanks to create a filter that includes costs only for the 'us-east-1' region and excludes 'Amazon S3' service.
Filter={'And': [{'Dimensions': {'Key': '[1]', 'Values': ['us-east-1']}}, {'Not': {'Dimensions': {'Key': '[2]', 'Values': ['Amazon S3']}}}]}The first filter uses 'REGION' to select 'us-east-1'. The second uses 'SERVICE' inside a 'Not' to exclude 'Amazon S3'.
Fill all three blanks to build a Cost Explorer query that groups by service, filters for costs greater than 10 USD, and uses monthly granularity.
response = client.get_cost_and_usage(TimePeriod={'Start': '2023-03-01', 'End': '2023-03-31'}, Granularity='[1]', Metrics=['UnblendedCost'], GroupBy=[{'Type': '[2]', 'Key': '[3]'}], Filter={'Numeric': {'Key': 'UnblendedCost', 'Operator': 'GREATER_THAN', 'Value': 10}})Granularity is 'MONTHLY' for monthly data. GroupBy type is 'DIMENSION' and key is 'SERVICE' to group costs by service.