Last active
March 15, 2022 16:00
-
-
Save alexcasalboni/b9b6c23b659f86591ac53bcc80c486cf to your computer and use it in GitHub Desktop.
AWS Pricing API - Fetch AWS Step Functions price for all regions
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
const AWS = require('aws-sdk'); | |
const pricing = new AWS.Pricing({region: 'us-east-1'}); | |
const main = async () => { | |
const output = {}; | |
const prices = await pricing.getProducts({ | |
ServiceCode: "AmazonStates", | |
}).promise(); | |
const products = prices.PriceList.filter(p => { | |
return p.product.attributes.groupDescription == "Number of State Transitions"; | |
}).forEach((p) => { | |
if (p.product.attributes.location == 'Any') | |
return; // just skip it | |
// see p.json below for the structure of each "product" | |
// there are two random keys under p.terms.OnDemand | |
const terms = p.terms.OnDemand; | |
const randomKey = Object.keys(terms)[0]; | |
const priceDimensions = terms[randomKey].priceDimensions; | |
const randomKey2 = Object.keys(priceDimensions)[0]; | |
const pricePerUnit = priceDimensions[randomKey2].pricePerUnit.USD; | |
const regionCode = regionsMapping[p.product.attributes.location]; | |
if (!regionCode) throw new Error("Unknown region: " + p.product.attributes.location); | |
output[regionCode] = parseFloat(pricePerUnit); | |
}); | |
console.log(JSON.stringify(output)); | |
}; | |
const regionsMapping = { | |
'AWS GovCloud (US-West)': 'us-gov-west-1', | |
'EU (Stockholm)': 'eu-north-1', | |
'EU (Frankfurt)': 'eu-central-1', | |
'US East (N. Virginia)': 'us-east-1', | |
'Asia Pacific (Tokyo)': 'ap-northeast-1', | |
'Asia Pacific (Seoul)': 'ap-northeast-2', | |
'EU (Milan)': 'eu-south-1', | |
'Africa (Cape Town)': 'af-south-1', | |
'US West (N. California)': 'us-west-1', | |
'EU (Paris)': 'eu-west-3', | |
'Asia Pacific (Sydney)': 'ap-southeast-2', | |
'Asia Pacific (Hong Kong)': 'ap-east-1', | |
'EU (London)': 'eu-west-2', | |
'Middle East (Bahrain)': 'me-south-1', | |
'US East (Ohio)': 'us-east-2', | |
'Asia Pacific (Mumbai)': 'ap-south-1', | |
'Asia Pacific (Singapore)': 'ap-southeast-1', | |
'AWS GovCloud (US-East)': 'us-gov-east-1', | |
'Canada (Central)': 'ca-central-1', | |
'EU (Ireland)': "eu-west-1", | |
'US West (Oregon)': "us-west-2", | |
'South America (Sao Paulo)': 'sa-east-1', | |
}; | |
main(); |
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
{ | |
"us-gov-west-1": 0.00003, | |
"eu-north-1": 0.000025, | |
"eu-central-1": 0.000025, | |
"us-east-1": 0.000025, | |
"ap-northeast-1": 0.000025, | |
"ap-northeast-2": 0.0000271, | |
"eu-south-1": 0.00002625, | |
"af-south-1": 0.00002975, | |
"us-west-1": 0.0000279, | |
"eu-west-3": 0.0000297, | |
"ap-southeast-2": 0.000025, | |
"ap-east-1": 0.0000275, | |
"eu-west-2": 0.000025, | |
"me-south-1": 0.0000275, | |
"us-east-2": 0.000025, | |
"ap-south-1": 0.0000285, | |
"ap-southeast-1": 0.000025, | |
"us-gov-east-1": 0.00003, | |
"ca-central-1": 0.000025, | |
"eu-west-1": 0.000025, | |
"us-west-2": 0.000025, | |
"sa-east-1": 0.0000375 | |
} |
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
{ | |
"product": { | |
"productFamily": "AWS Step Functions", | |
"attributes": { | |
"group": "SFN-StateTransitions", | |
"locationType": "AWS Region", | |
"usagetype": "EU-StateTransition", | |
"servicename": "AWS Step Functions", | |
"location": "EU (Ireland)", | |
"operation": "", | |
"groupDescription": "Number of State Transitions", | |
"servicecode": "AmazonStates" | |
}, | |
"sku": "XGGWEYVMS82UQ68Y" | |
}, | |
"version": "20200427230151", | |
"terms": { | |
"OnDemand": { | |
"XGGWEYVMS82UQ68Y.JRTCKXETXF": { | |
"sku": "XGGWEYVMS82UQ68Y", | |
"termAttributes": {}, | |
"offerTermCode": "JRTCKXETXF", | |
"effectiveDate": "2020-04-01T00:00:00Z", | |
"priceDimensions": { | |
"XGGWEYVMS82UQ68Y.JRTCKXETXF.6YS6EN2CT7": { | |
"description": "$0.000025 per state transition", | |
"appliesTo": [], | |
"rateCode": "XGGWEYVMS82UQ68Y.JRTCKXETXF.6YS6EN2CT7", | |
"unit": "StateTransitions", | |
"beginRange": "0", | |
"pricePerUnit": { | |
"USD": "0.0000250000" | |
}, | |
"endRange": "Inf" | |
} | |
} | |
} | |
} | |
}, | |
"serviceCode": "AmazonStates", | |
"publicationDate": "2020-04-27T23:01:51Z" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment