aws-cost-calculator-cli 1.5.2__py3-none-any.whl → 2.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aws-cost-calculator-cli
3
- Version: 1.5.2
3
+ Version: 2.4.0
4
4
  Summary: AWS Cost Calculator CLI - Calculate daily and annual AWS costs across multiple accounts
5
- Home-page: https://github.com/yourusername/cost-calculator
5
+ Home-page: https://github.com/trilogy-group/aws-cost-calculator
6
6
  Author: Cost Optimization Team
7
7
  Author-email:
8
- Project-URL: Documentation, https://github.com/yourusername/cost-calculator/blob/main/README.md
8
+ Project-URL: Documentation, https://github.com/trilogy-group/aws-cost-calculator/blob/main/README.md
9
9
  Keywords: aws cost calculator billing optimization cloud
10
10
  Classifier: Development Status :: 4 - Beta
11
11
  Classifier: Intended Audience :: Developers
@@ -43,66 +43,209 @@ A CLI tool to quickly calculate AWS costs across multiple accounts.
43
43
  ## Installation
44
44
 
45
45
  ```bash
46
- cd ~/cost-calculator
47
- pip install -e .
46
+ pip install aws-cost-calculator-cli
47
+ ```
48
+
49
+ Or upgrade to the latest version:
50
+ ```bash
51
+ pip install --upgrade aws-cost-calculator-cli
48
52
  ```
49
53
 
50
54
  ## Quick Start
51
55
 
52
- ### 1. Login to AWS SSO
56
+ ### Authentication Methods
57
+
58
+ The CLI supports three authentication methods:
53
59
 
60
+ #### 1. SSO (Recommended)
54
61
  ```bash
55
- aws sso login --profile my_aws_profile
62
+ # The CLI will automatically trigger SSO login if needed
63
+ cc calculate --profile myprofile --sso my_sso_profile
56
64
  ```
57
65
 
58
- **Note:** You need to do this before running cost calculations. The SSO session typically lasts 8-12 hours.
59
-
60
- ### 2. Initialize a profile
66
+ #### 2. Static Credentials
67
+ ```bash
68
+ cc calculate --profile myprofile \
69
+ --access-key-id ASIA... \
70
+ --secret-access-key ... \
71
+ --session-token ...
72
+ ```
61
73
 
74
+ #### 3. Environment Variables
62
75
  ```bash
63
- cc init --profile myprofile \
64
- --aws-profile my_aws_profile \
65
- --accounts "123456789012,234567890123,345678901234"
76
+ # For SSO
77
+ export AWS_PROFILE=my_sso_profile
78
+ cc calculate --profile myprofile
79
+
80
+ # For static credentials
81
+ export AWS_ACCESS_KEY_ID=ASIA...
82
+ export AWS_SECRET_ACCESS_KEY=...
83
+ export AWS_SESSION_TOKEN=...
84
+ cc calculate --profile myprofile
66
85
  ```
67
86
 
68
- ### 3. Calculate costs
87
+ ### Basic Usage
69
88
 
70
89
  ```bash
71
90
  # Default: Today minus 2 days, going back 30 days
72
- cc calculate --profile myprofile
91
+ cc calculate --profile myprofile --sso my_sso_profile
73
92
 
74
93
  # Specific start date
75
- cc calculate --profile myprofile --start-date 2025-11-04
94
+ cc calculate --profile myprofile --sso my_sso_profile --start-date 2025-11-04
76
95
 
77
96
  # Custom offset and window
78
- cc calculate --profile myprofile --offset 2 --window 30
97
+ cc calculate --profile myprofile --sso my_sso_profile --offset 2 --window 30
79
98
 
80
99
  # JSON output
81
- cc calculate --profile myprofile --json-output
100
+ cc calculate --profile myprofile --sso my_sso_profile --json-output
82
101
  ```
83
102
 
84
103
  ### 4. Analyze cost trends
85
104
 
105
+ All commands support the same authentication options:
106
+
86
107
  ```bash
87
- # Analyze last 3 weeks (default)
108
+ # With SSO
109
+ cc trends --profile myprofile --sso my_sso_profile
110
+
111
+ # With static credentials
112
+ cc trends --profile myprofile --access-key-id ASIA... --secret-access-key ... --session-token ...
113
+
114
+ # With environment variables
115
+ export AWS_PROFILE=my_sso_profile
88
116
  cc trends --profile myprofile
89
117
 
90
118
  # Analyze more weeks
91
- cc trends --profile myprofile --weeks 5
119
+ cc trends --profile myprofile --sso my_sso_profile --weeks 5
92
120
 
93
121
  # Custom output file
94
- cc trends --profile myprofile --output weekly_trends.md
122
+ cc trends --profile myprofile --sso my_sso_profile --output weekly_trends.md
95
123
 
96
124
  # JSON output
97
- cc trends --profile myprofile --json-output
125
+ cc trends --profile myprofile --sso my_sso_profile --json-output
126
+ ```
127
+
128
+ ### 5. Monthly and drill-down analysis
129
+
130
+ ```bash
131
+ # Monthly trends
132
+ cc monthly --profile myprofile --sso my_sso_profile
133
+
134
+ # Drill down by service
135
+ cc drill --profile myprofile --sso my_sso_profile --service "EC2 - Other"
136
+
137
+ # Drill down by account
138
+ cc drill --profile myprofile --sso my_sso_profile --account 123456789012
98
139
  ```
99
140
 
100
- ### 5. List profiles
141
+ ### 6. List profiles
101
142
 
102
143
  ```bash
103
144
  cc list-profiles
104
145
  ```
105
146
 
147
+ ## Authentication
148
+
149
+ ### Overview
150
+
151
+ The CLI supports three authentication methods, all of which work with every command (`calculate`, `trends`, `monthly`, `drill`):
152
+
153
+ ### Method 1: SSO (Recommended)
154
+
155
+ The CLI automatically handles SSO login if your session has expired:
156
+
157
+ ```bash
158
+ cc calculate --profile myprofile --sso my_sso_profile
159
+ ```
160
+
161
+ **How it works:**
162
+ 1. CLI checks if SSO session is valid using `aws sts get-caller-identity`
163
+ 2. If expired, automatically runs `aws sso login --profile my_sso_profile`
164
+ 3. Opens browser for authentication
165
+ 4. Proceeds with cost calculation once authenticated
166
+
167
+ **Benefits:**
168
+ - No manual SSO login required
169
+ - Automatic session refresh
170
+ - Most secure method
171
+ - Works with AWS IAM Identity Center
172
+
173
+ ### Method 2: Static Credentials
174
+
175
+ Pass temporary credentials directly via CLI flags:
176
+
177
+ ```bash
178
+ cc calculate --profile myprofile \
179
+ --access-key-id ASIA... \
180
+ --secret-access-key ... \
181
+ --session-token ...
182
+ ```
183
+
184
+ **Use cases:**
185
+ - CI/CD pipelines
186
+ - Temporary credentials from STS
187
+ - Automated scripts
188
+ - When SSO is not available
189
+
190
+ ### Method 3: Environment Variables
191
+
192
+ Set credentials in your shell environment:
193
+
194
+ ```bash
195
+ # For SSO
196
+ export AWS_PROFILE=my_sso_profile
197
+ cc calculate --profile myprofile
198
+
199
+ # For static credentials
200
+ export AWS_ACCESS_KEY_ID=ASIA...
201
+ export AWS_SECRET_ACCESS_KEY=...
202
+ export AWS_SESSION_TOKEN=...
203
+ cc calculate --profile myprofile
204
+ ```
205
+
206
+ **Benefits:**
207
+ - No need to pass credentials with each command
208
+ - Works with existing AWS CLI configuration
209
+ - Can be set in shell profile (~/.zshrc, ~/.bashrc)
210
+
211
+ ### Profile Configuration
212
+
213
+ **v2.3.0+: API-Only Architecture**
214
+
215
+ All profiles are now managed via backend API (DynamoDB). No local profile files are used.
216
+
217
+ **Setup:**
218
+ ```bash
219
+ # Configure API secret (one-time setup)
220
+ cc configure --api-secret YOUR_SECRET
221
+
222
+ # Or set environment variable
223
+ export COST_API_SECRET=your_secret_here
224
+ ```
225
+
226
+ **List available profiles:**
227
+ ```bash
228
+ cc list-profiles
229
+ ```
230
+
231
+ **How it works:**
232
+ 1. CLI gets AWS credentials from SSO/environment
233
+ 2. CLI sends request to `https://api.costcop.cloudfix.dev` with:
234
+ - Profile name (e.g., "khoros")
235
+ - Your AWS credentials
236
+ 3. Backend Lambda loads profile from DynamoDB (accounts, exclusions, Athena config)
237
+ 4. Backend executes AWS API calls using your credentials
238
+ 5. Results returned to CLI for formatting
239
+
240
+ **Benefits:**
241
+ - No local configuration files to maintain
242
+ - Centralized profile management
243
+ - Automatic exclusions (Tax, Support, etc.)
244
+ - Profile updates apply immediately to all users
245
+ - Athena CUR configuration managed centrally
246
+
247
+ The CLI will automatically fetch profile configuration from the backend if `COST_API_SECRET` is set.
248
+
106
249
  ## How It Works
107
250
 
108
251
  ### Date Calculation
@@ -240,11 +383,13 @@ The `drill` command allows you to investigate cost changes at different levels o
240
383
  1. **Start broad:** `cc trends` → See EC2 costs up $1000
241
384
  2. **Drill by service:** `cc drill --service "EC2 - Other"` → See which accounts
242
385
  3. **Drill deeper:** `cc drill --service "EC2 - Other" --account 123` → See usage types
386
+ 4. **Resource-level:** `cc drill --service "EC2 - Other" --account 123 --resources` → See individual instance IDs
243
387
 
244
388
  **Features:**
245
389
  - **Week-over-week cost analysis**: Compare costs between consecutive weeks
246
390
  - **Month-over-month cost analysis**: Compare costs between consecutive months
247
391
  - **Drill-down analysis**: Analyze costs by service, account, or usage type
392
+ - **Resource-level analysis**: See individual resource IDs and costs using CUR data (NEW in v1.7.0)
248
393
  - **Pandas aggregations**: Time series analysis with sum, avg, std across all weeks
249
394
  - **Volatility detection**: Identify services with high cost variability and outliers
250
395
  - **Trend detection**: Auto-detect increasing/decreasing cost patterns
@@ -262,7 +407,7 @@ cc drill --profile myprofile --service "EC2 - Other"
262
407
  Showing top accounts:
263
408
  Week of Oct 19 → Week of Oct 26
264
409
  Increases: 3, Decreases: 2
265
- Top: 887649220066 (+$450.23)
410
+ Top: 123456789012 (+$450.23)
266
411
  ```
267
412
 
268
413
  The report is saved to `drill_down.md` by default.
@@ -0,0 +1,16 @@
1
+ aws_cost_calculator_cli-2.4.0.dist-info/licenses/LICENSE,sha256=cYtmQZHNGGTXOtg3T7LHDRneleaH0dHXHfxFV3WR50Y,1079
2
+ cost_calculator/__init__.py,sha256=PJeIqvWh5AYJVrJxPPkI4pJnAt37rIjasrNS0I87kaM,52
3
+ cost_calculator/api_client.py,sha256=UN_dKo8OYWVN905xZAn8pLlHMBSFR_EJWCUq21K8IKg,2204
4
+ cost_calculator/cli.py,sha256=eFk3sjNBdupZHlivhWSpxAWZluDyzX-OHM_EycfJrbk,98144
5
+ cost_calculator/cur.py,sha256=QaZ_nyDSw5_cti-h5Ho6eYLbqzY5TWoub24DpyzIiSs,9502
6
+ cost_calculator/dimensions.py,sha256=cTpdYm-w88IgqlcB4ObhUsvGREBMrMSZx0d2PyehI6M,4478
7
+ cost_calculator/drill.py,sha256=hGi-prLgZDvNMMICQc4fl3LenM7YaZ3To_Ei4LKwrdc,10543
8
+ cost_calculator/executor.py,sha256=vwp4SoZfTobUeTKPujRzZzkO7tjOG8_LEGxgtraOZAQ,9348
9
+ cost_calculator/forensics.py,sha256=uhRo3I_zOeMEaBENHfgq65URga31W0Z4vzS2UN6VmTY,12819
10
+ cost_calculator/monthly.py,sha256=6k9F8S7djhX1wGV3-T1MZP7CvWbbfhSTEaddwCfVu5M,7932
11
+ cost_calculator/trends.py,sha256=k_s4ylBX50sqoiM_fwepi58HW01zz767FMJhQUPDznk,12246
12
+ aws_cost_calculator_cli-2.4.0.dist-info/METADATA,sha256=CF6_PkZ3eigTW-F6uKHaCtztSCqu_tnKN8Z9FzSTVS4,12160
13
+ aws_cost_calculator_cli-2.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ aws_cost_calculator_cli-2.4.0.dist-info/entry_points.txt,sha256=_5Qy4EcHbYVYrdgOu1E48faMHb9fLUl5VJ3djDHuJBo,47
15
+ aws_cost_calculator_cli-2.4.0.dist-info/top_level.txt,sha256=PRwGPPlNqASfyhGHDjSfyl4SXeE7GF3OVTu1tY1Uqyc,16
16
+ aws_cost_calculator_cli-2.4.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.7.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -23,14 +23,15 @@ def get_api_config():
23
23
  return None
24
24
 
25
25
 
26
- def call_lambda_api(endpoint, credentials, accounts, **kwargs):
26
+ def call_lambda_api(endpoint, credentials, accounts=None, profile=None, **kwargs):
27
27
  """
28
- Call Lambda API endpoint.
28
+ Call unified API Gateway endpoint.
29
29
 
30
30
  Args:
31
- endpoint: API endpoint name ('trends', 'monthly', 'drill')
31
+ endpoint: API endpoint name ('calculate', 'trends', 'monthly', 'drill', 'query', etc.)
32
32
  credentials: dict with AWS credentials
33
- accounts: list of account IDs
33
+ accounts: list of account IDs (deprecated - use profile instead)
34
+ profile: profile name (preferred over accounts)
34
35
  **kwargs: additional parameters for the specific endpoint
35
36
 
36
37
  Returns:
@@ -44,25 +45,22 @@ def call_lambda_api(endpoint, credentials, accounts, **kwargs):
44
45
  if not api_config:
45
46
  raise Exception("API not configured. Set COST_API_SECRET environment variable.")
46
47
 
47
- # Map endpoint names to Lambda URLs
48
- endpoint_urls = {
49
- 'trends': 'https://pq3mqntc6vuwi4zw5flulsoleq0yiqtl.lambda-url.us-east-1.on.aws/',
50
- 'monthly': 'https://6aueebodw6q4zdeu3aaexb6tle0fqhhr.lambda-url.us-east-1.on.aws/',
51
- 'drill': 'https://3ncm2gzxrsyptrhud3ua3x5lju0akvsr.lambda-url.us-east-1.on.aws/',
52
- 'analyze': 'https://y6npmidtxwzg62nrqzkbacfs5q0edwgs.lambda-url.us-east-1.on.aws/',
53
- 'profiles': 'https://64g7jq7sjygec2zmll5lsghrpi0txrzo.lambda-url.us-east-1.on.aws/'
54
- }
55
-
56
- url = endpoint_urls.get(endpoint)
57
-
58
- if not url:
59
- raise Exception(f"Unknown endpoint: {endpoint}")
48
+ # Get base URL from environment or use default
49
+ base_url = os.environ.get('COST_CALCULATOR_API_URL', 'https://api.costcop.cloudfix.dev')
50
+ url = f"{base_url}/{endpoint}"
60
51
 
61
52
  # Build request payload
62
53
  payload = {
63
- 'credentials': credentials,
64
- 'accounts': accounts
54
+ 'credentials': credentials
65
55
  }
56
+
57
+ # Add profile or accounts
58
+ if profile:
59
+ payload['profile'] = profile
60
+ elif accounts:
61
+ payload['accounts'] = accounts
62
+
63
+ # Add additional parameters
66
64
  payload.update(kwargs)
67
65
 
68
66
  # Make API call
@@ -71,7 +69,7 @@ def call_lambda_api(endpoint, credentials, accounts, **kwargs):
71
69
  'Content-Type': 'application/json'
72
70
  }
73
71
 
74
- response = requests.post(url, headers=headers, json=payload, timeout=300)
72
+ response = requests.post(url, headers=headers, json=payload, timeout=900) # 15 min timeout
75
73
 
76
74
  if response.status_code != 200:
77
75
  raise Exception(f"API call failed: {response.status_code} - {response.text}")