Created
September 26, 2020 17:51
-
-
Save isaacjwilliams/2a12dc0acc562353a6b58c5afcf1faf8 to your computer and use it in GitHub Desktop.
Lambda Provisioned Concurrency Cost Calculator
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
| // Global | |
| const secondsPerMonth = 31 * 24 * 3600; | |
| // Lambda (based on: https://aws.amazon.com/lambda/pricing/) | |
| const costPerProvisionedGbs = 0.0000041667; | |
| const costPerMillionRequests = 0.20; | |
| const costPerProvisionedDurationGbs = 0.0000097222; | |
| const costPerDurationGbs = 0.0000166667; | |
| // Warmer | |
| const healthCheckDurationSeconds = 1; | |
| const secondsBetweenWarmerInvocations = 60; | |
| function provisionedConcurrencyCost({ | |
| lambdaMemorySizeMb, | |
| provisionedConcurrency, | |
| secondsEnabled | |
| }) { | |
| const provisionedGb = provisionedConcurrency * (lambdaMemorySizeMb / 1024); | |
| const provisionedGbs = provisionedGb * secondsEnabled; | |
| return provisionedGbs * costPerProvisionedGbs; | |
| } | |
| function computeCost({ lambdaMemorySizeMb, millionRequests, duration, provisioned }) { | |
| const computeSeconds = (millionRequests * 1000000) * duration; | |
| const computeGbs = computeSeconds * (lambdaMemorySizeMb / 1024); | |
| return computeGbs * (provisioned ? costPerProvisionedDurationGbs : costPerDurationGbs); | |
| } | |
| function requestCost({ lambdaMemorySizeMb, millionRequests, duration, provisioned }) { | |
| return (millionRequests * costPerMillionRequests) + | |
| computeCost({ lambdaMemorySizeMb, millionRequests, duration, provisioned }); | |
| } | |
| function manualWarmingCost({ lambdaMemorySizeMb, provisionedConcurrency, secondsEnabled }) { | |
| const warmingRequestsPerConcurrency = secondsEnabled / secondsBetweenWarmerInvocations; | |
| const warmingRequests = provisionedConcurrency * warmingRequestsPerConcurrency; | |
| const millionRequests = warmingRequests / 1000000; | |
| return requestCost({ | |
| lambdaMemorySizeMb, | |
| millionRequests, | |
| duration: healthCheckDurationSeconds, | |
| provisioned: false | |
| }); | |
| } | |
| function roundCost(cost) { | |
| return Math.round(cost * 100) / 100; | |
| } | |
| const args = { | |
| lambdaMemorySizeMb: 256, | |
| provisionedConcurrency: 100, | |
| secondsEnabled: secondsPerMonth | |
| }; | |
| console.log({ | |
| args, | |
| provisionedCost: roundCost(provisionedConcurrencyCost(args)), | |
| warmerCost: roundCost(manualWarmingCost(args)) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment