Skip to content

Instantly share code, notes, and snippets.

@ehoppmann
Created August 29, 2018 16:35
Show Gist options
  • Save ehoppmann/61905422e5d300212c677a41c6143cde to your computer and use it in GitHub Desktop.
Save ehoppmann/61905422e5d300212c677a41c6143cde to your computer and use it in GitHub Desktop.
Compute lambda cost from logs downloaded using awslogs
COST_GB_SEC = 0.00001667
cost = 0
with open('logs.log', 'r') as f:
logs = f.readlines()
billing = [i.split('\t') for i in logs if '\tBilled Duration:' in i]
for i in billing:
gb = float(i[3].lstrip('Memory Size: ').rstrip(' MB')) / 1024
sec = float(i[2].lstrip('Billed Duration: ').rstrip(' ms ')) / 1000
gb_sec = gb * sec
cost += gb_sec * COST_GB_SEC
print(cost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment