Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vduseev/aws-ec2-pricing
Command line tool to collect EC2 prices from AWS API and put them into SQLite table to analyze them better
https://github.com/vduseev/aws-ec2-pricing
aws command-line ec2 pricing python sql table
Last synced: 23 days ago
JSON representation
Command line tool to collect EC2 prices from AWS API and put them into SQLite table to analyze them better
- Host: GitHub
- URL: https://github.com/vduseev/aws-ec2-pricing
- Owner: vduseev
- License: apache-2.0
- Created: 2021-09-14T07:27:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-27T00:20:21.000Z (12 months ago)
- Last Synced: 2024-08-08T16:11:13.749Z (3 months ago)
- Topics: aws, command-line, ec2, pricing, python, sql, table
- Language: Python
- Homepage:
- Size: 891 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-ec2-pricing
![Table of AWS EC2 prices in SQL](/docs/example-query.png)
Collect AWS EC2 prices from AWS API to SQL table to analyze them.
**Table of contents**:
* Usage
* download
* build
* Installation
* Working with data
* Table columns and meaning
* How to run queries
* Limitations
* Future plans## Usage
Make sure AWS credentials are set as environment variables or are available otherwise to `boto3` library
which this program uses to connect to AWS API.The AWS Price List Query API is [not available in all regions](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/using-price-list-query-api.html#price-list-query-api-endpoints); this program defaults to using the API endpoint in `us-east-1` (N. Virginia), and permits changing regions to the other available endpoints (`eu-central-1`, Frankfurt; `ap-south-1`, Mumbai) using the `--region` option.
```shell
Usage: ec2pricing [OPTIONS] COMMAND [ARGS]...Options:
--version Show the version and exit.
-r, --region [us-east-1|eu-central-1|ap-south-1]
The AWS region to use. Limited to specific
regions where the Pricing API is available;
default: us-east-1
--help Show this message and exit.Commands:
build Build SQLite database with prices from given JSON
download Download EC2 prices to JSON file
```
Download all "On Demand" prices for all regions for "Shared" instances into a JSON file.```shell
ec2pricing download
```
Build a SQLite database from that JSON file.*You can see an example of built database in `examples/prices.db` file in this repo.*
```shell
ec2pricing build
```The resulting file is a SQLite database with a single `prices` table in it.
Resulting table `prices` in the `prices.db` file has following columns:NameDescriptionExamples
familyInstace familyGeneral purpose, Compute optimized
typeInstace type groupa1, t3a, c5
sizeInstace sizenano, micro, xlarge, 32xlarge
burstIs instance burstable?Yes, No
baseBaseline performance of CPU (%)5, 10, 100
processorName of the physical CPUAWS Graviton, AMD EPYC
bitCPU bitness32-bit, 64-bit
archCPU architecturearm, x86
tenancyInstance tenancyShared, Dedicated, Host
regionAWS RegionUS East (Ohio), EU (Ireland)
vcpuNumber of virtual cores1, 2, 32
memoryAmount of RAM0.5 GiB, 128 GiB
storageStorage typeEBS only, 1x60GB NVM
osOperating SystemLinux
normNormalization scale factor (used by AWS to compare instances)0.5, 1.0, 8.0
speedDeclared CPU clock speed2.5 GHz, Up to 3.2 Ghz. 0 GHz
actualActual CPU clock speed multiplied by baseline0.125 GHz, 2.5 Ghz
networkNetwork performanceUp to 3500 MiB
genIs it current generation of instances?Yes, No
curPrice currencyUSD, CNY
hourlyHourly price0.0255
montlyMonthly price (hourly * 24 * 30)3.844
startingDate from which Amazon offers this price2021-09-01T00:00:00Z
The built database can be opened in any SQL IDE, for example, DBeaver (open source SQL editor) or in any other way.
You can then run queries in it.**Show cheapest x86-64 virtual machines**:
```sql
SELECT * FROM prices WHERE arch = 'x86'
ORDER BY monthly;
```**Show cheapest ARM machines in Ireland**:
```sql
SELECT * FROM prices
WHERE arch = 'arm' AND region = "EU (Ireland)"
ORDER BY monthly;
```**Sort all machines alpabetically by their family, type and power**:
```sql
SELECT * FROM prices
ORDER BY family, type, norm;
```## Limitations
Currently, downloaded prices are limited to instances with:
* "Shared" tenancy
* "Linux" operating system
* Support for VPC networking
* Only "On Demand" pricing, no reserved instances or saving plans
* "Used" capacity reservationAll these are default settings for EC2 instances when you check prices for them on AWS pricng website.
## Installation
This program is written in Python and can be installed via `pip`.
```shell
pip install aws-ec2-pricing
```## Build it and run it yourself
### Set up via pip and virtual environemnt
* Create a virtual environment
```shell
python3 -m venv .venv
source ./.venv/bin/activate
```* Install requirements into it
```shell
pip install -r requirements.txt
```* Run the program
```shell
python3 ec2pricing/__init__.py download
```### Set up via poetry
* Tell poetry which version of python available in your system to use
```shell
poetry env use 3.9.7
```* Install dependencies and create virtual environment
```shell
poetry install
```* Run program
```shell
poetry run ec2pricing download
```## Feature plans
* [ ] Static website that displays the table along with the filters
* [ ] Add search filters as key-value pairs for initial price download
* [ ] Search for instances other than shared or Linux based
* [ ] Support saving plans, reserved instances, free tier## Copyright & License
* This program is distributed under Apache 2 License.
* All AWS and Amazon related trademarks or symbols are not mine.
* Prices obtained through this program are not an offer and should not be treated as official.