github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/platform/aws/cost/cost.go (about) 1 // Package cost provides utilities for calculating AWS Lambda pricing. 2 package cost 3 4 // pricePerInvoke is the cost per function invocation. 5 var pricePerInvoke = 0.0000002 6 7 // pricePerRequestUnit is the cost per api gateway request unit. 8 var pricePerRequestUnit = 5 9 10 // requestUnit is 5 million requests. 11 var requestUnit = 5e6 12 13 // memoryConfigurations available. 14 var memoryConfigurations = map[int]float64{ 15 128: 0.000000208, 16 192: 0.000000313, 17 256: 0.000000417, 18 320: 0.000000521, 19 384: 0.000000625, 20 448: 0.000000729, 21 512: 0.000000834, 22 576: 0.000000938, 23 640: 0.000001042, 24 704: 0.000001146, 25 768: 0.00000125, 26 832: 0.000001354, 27 896: 0.000001459, 28 960: 0.000001563, 29 1024: 0.000001667, 30 1088: 0.000001771, 31 1152: 0.000001875, 32 1216: 0.00000198, 33 1280: 0.000002084, 34 1344: 0.000002188, 35 1408: 0.000002292, 36 1472: 0.000002396, 37 1536: 0.000002501, 38 } 39 40 // Requests returns the cost for the given number of http requests. 41 func Requests(n int) float64 { 42 return (float64(n) / float64(requestUnit)) * float64(pricePerRequestUnit) 43 } 44 45 // Rate returns the cost per 100ms for the given `memory` configuration in megabytes. 46 func Rate(memory int) float64 { 47 return memoryConfigurations[memory] 48 } 49 50 // Invocations returns the cost of `n` requests. 51 func Invocations(n int) float64 { 52 return pricePerInvoke * float64(n) 53 } 54 55 // Duration returns the cost of `ms` for the given `memory` configuration in megabytes. 56 func Duration(ms, memory int) float64 { 57 return Rate(memory) * (float64(ms) / 100) 58 }