Skip to content

Instantly share code, notes, and snippets.

@azat
Created February 5, 2023 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/9f3fbf59c6f5ad42c5ae9a0d9a971e77 to your computer and use it in GitHub Desktop.
Save azat/9f3fbf59c6f5ad42c5ae9a0d9a971e77 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Compare prices for cloud storage providers:
# - S3 - AWS S3 from Amazon
# https://aws.amazon.com/s3/pricing/
# - GS/GCS - Google Cloud Storage
# https://cloud.google.com/storage/pricing#north-america
# - R2 - R2 from CloudFrame
# https://developers.cloudflare.com/r2/platform/pricing/
import sys
def ranged_price(value, ranges):
cost = 0
for limit, price in reversed(ranges.items()):
if value > limit:
cost += (value - limit) * price
value = limit
return cost
def r2(size_gb):
return size_gb*0.015
def s3(size_gb):
price_ranges = {
0: 0.023,
50*1024: 0.022,
500*1024: 0.021,
}
return ranged_price(size_gb, price_ranges)
def gs(size_gb):
return size_gb * 0.020
def gs_egress(size_gb):
price_ranges = {
0: 0.12,
1*1024: 0.11,
10*1024: 0.08,
}
return ranged_price(size_gb, price_ranges)
size_gb = int(sys.argv[1])
print('### Cost')
print('- r2: {:,}$'.format(r2(size_gb)))
print('- s3: {:,}$'.format(s3(size_gb)))
print('- gs: {:,}$'.format(gs(size_gb) + gs_egress(size_gb)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment