aws-spot-price
v1.1.28
Published
CLI utility to list current global AWS EC2 Spot Instance prices.
Downloads
721
Maintainers
Readme
aws-spot-price
Lists current global AWS EC2 Spot Instance prices.
Supports CLI and module usage.
CLI
Example
Installation
npm
npm i aws-spot-price
yarn
yarn add aws-spot-price
run with npx
npx aws-spot-price
run with yarn dlx
yarn dlx aws-spot-price
Usage
aws-spot-run [options]
If no options are applied, it will fetch all recent pricing data from default regions and show top 30 cheapest instances.
Credentials
This CLI utility uses AWS-SDK and requires AWS Access & Secret keys. If environment variables pair AWS_ACCESS_KEY_ID
& AWS_SECRET_ACCESS_KEY
or ~/.aws/credentials
is available it will use it. Otherwise, you will need to supply credentials through CLI options --accessKeyId
and --secretAccessKey
.
Permissions Required
- ec2:DescribeSpotPriceHistory
- ec2:DescribeInstanceTypes
Options
--ui
Start with UI mode.
--region | -r
AWS region to fetch data from. Accepts multiple string values. Defaults to all available AWS region which does not require opt-in.
example -r us-east-1 us-east-2
--family
EC2 instance families to filter. Will be translated to --familyType
and --size
values.
Accepts multiple string values.
Choose from: general
, compute
, memory
, storage
, acceleratedComputing
example -f general compute
--instanceType | -i
Type of EC2 instance to filter. Accepts multiple string values. Enter valid EC2 instance type name.
example -i t3.nano t3a.nano
--familyType | -f
EC2 Family type (c4
, c5
, etc..). Accepts multiple string values.
example -f c4 c5
--size | -s
EC2 size (large
, xlarge
, etc..). Accepts multiple string values.
example -s large xlarge
--minVCPU | --mc
Minimum vCPU count
Default: 1
--minMemoryGiB | --mm
Minimum memory size in GiB
Default: 0.5
--priceLimit | --pl
Maximum price limit.
Default: 100
--platforms | -p
Instance platforms types to filter. Accepts multiple string values.
You can use linux
or windows
(all in lowercase) as wildcard.
Default: "Linux/UNIX" "Linux/UNIX (Amazon VPC)"
example -p windows "Red Hat Enterprise Linux"
--architectures | -a
Instance architecture types to filter. Accepts multiple string values.
Default: "arm64","arm64_mac","i386","x86_64","x86_64_mac"
example -a arm64 x86_64
--limit | -l
Limits list of price information items to be returned.
Default: 30
--reduceAZ | --raz
Reduce results with cheapest Availability Zone within Region
Default: true
--wide | -w
Output results with detail (vCPU, memory, etc)
Default: false
--json | -j
Outputs in JSON format. This option will silence any progress output.
--accessKeyId
Specific AWS Access Key ID. Requires --secretAccessKey
option to be used together.
--secretAccessKey
Specific AWS Secret Access Key. Requires --accessKeyId
option to be used together.
Module
Installation
npm
npm i aws-spot-price
yarn
yarn add aws-spot-price
Example
Code
import { getGlobalSpotPrices } from 'aws-spot-price';
(async () => {
const results = await getGlobalSpotPrices({
regions: ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'],
familyTypes: ['c5', 'c5a', 'c5ad', 'c5d', 'c5n', 'c6g', 'c6gd'],
minMemoryGiB: 4,
minVCPU: 2,
limit: 5,
reduceAZ: true,
architectures: ['arm64', 'x86_64']
});
console.log(JSON.stringify(results, null, 2));
})();
Results
[
{
"availabilityZone": "us-east-2c",
"instanceType": "t4g.medium",
"platform": "Linux/UNIX",
"architectures": [
"arm64"
],
"spotPrice": 0.0083,
"timestamp": "2024-05-16T10:31:10.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-west-2a",
"instanceType": "c7a.large",
"platform": "Linux/UNIX",
"architectures": [
"x86_64"
],
"spotPrice": 0.0103,
"timestamp": "2024-05-15T16:09:23.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-west-1b",
"instanceType": "c7i-flex.large",
"platform": "Linux/UNIX",
"architectures": [
"x86_64"
],
"spotPrice": 0.0108,
"timestamp": "2024-05-16T04:16:55.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-west-2d",
"instanceType": "m7a.large",
"platform": "Linux/UNIX",
"architectures": [
"x86_64"
],
"spotPrice": 0.0117,
"timestamp": "2024-05-16T00:47:33.000Z",
"vCpu": 2,
"memoryGiB": 8
},
{
"availabilityZone": "us-west-2b",
"instanceType": "t3a.medium",
"platform": "Linux/UNIX",
"architectures": [
"x86_64"
],
"spotPrice": 0.0129,
"timestamp": "2024-05-16T09:02:05.000Z",
"vCpu": 2,
"memoryGiB": 4
}
]