Created
          August 29, 2018 16:35 
        
      - 
      
- 
        Save ehoppmann/61905422e5d300212c677a41c6143cde to your computer and use it in GitHub Desktop. 
    Compute lambda cost from logs downloaded using awslogs
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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