Last active
December 11, 2023 22:01
-
-
Save unacceptable/dbf000ce4fde4b14a45d315507de5cd7 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
''' | |
Calculate AWS Fargate pricing | |
''' | |
import argparse | |
import logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format='%(asctime)s %(levelname)s %(message)s' | |
) | |
def main(args): | |
''' | |
Main function | |
''' | |
pricing = get_pricing() | |
logging.debug('Pricing: %s', pricing) | |
cpu_cost = pricing['vcpu'] * args.cpu | |
logging.info('CPU cost (per pod-hour): $%.6f', cpu_cost) | |
memory_cost = pricing['memory'] * args.memory | |
logging.info('Memory cost (per pod-hour): $%.6f', memory_cost) | |
hours_per_month = args.days * args.hours | |
total_cost = args.count * (cpu_cost + memory_cost) * hours_per_month | |
logging.info("Total cost: $%.6f (%d pods up %.2f hours/month)", total_cost, args.count, hours_per_month) | |
return total_cost | |
def get_pricing(): | |
''' | |
Get pricing for AWS Fargate in Oregon (us-west-2) | |
https://aws.amazon.com/fargate/pricing/ | |
This needs to be more dynamic in the future. | |
''' | |
return { | |
'vcpu': 0.012144, | |
'memory': 0.0013335, | |
} | |
def parse_args(): | |
''' | |
Parse command line arguments | |
''' | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--count", | |
help="Number of pods to run", | |
type=int, | |
default=1 | |
) | |
parser.add_argument( | |
"--cpu", | |
help="vCPU cores per pod", | |
type=float, | |
default=0.1 | |
) | |
parser.add_argument( | |
"--memory", | |
help="Memory per pod (GB)", | |
type=float, | |
default=0.05 | |
) | |
parser.add_argument( | |
"--days", | |
help="Days to run per month", | |
type=int, | |
default=30 | |
) | |
parser.add_argument( | |
"--hours", | |
help="Hours to run per day", | |
type=float, | |
default=24 | |
) | |
logging.debug('Parsing arguments: %s', parser.parse_args()) | |
return parser.parse_args() | |
if __name__ == "__main__": | |
args = parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment