Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module with architecture #843

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ You can use `linux` or `windows` (all in lowercase) as wildcard.

###### _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.
Expand Down Expand Up @@ -173,56 +181,73 @@ import { getGlobalSpotPrices } from 'aws-spot-price';
minVCPU: 2,
limit: 5,
reduceAZ: true,
architectures: ['arm64', 'x86_64']
});
console.log(JSON.stringify(results, null, 2));
})();
```

#### Results

```json[
```json
[
{
"availabilityZone": "us-east-2c",
"instanceType": "c5.large",
"instanceType": "t4g.medium",
"platform": "Linux/UNIX",
"spotPrice": 0.019,
"timestamp": "2020-11-19T15:18:07.000Z",
"architectures": [
"arm64"
],
"spotPrice": 0.0083,
"timestamp": "2024-05-16T10:31:10.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-east-2c",
"instanceType": "c5a.large",
"availabilityZone": "us-west-2a",
"instanceType": "c7a.large",
"platform": "Linux/UNIX",
"spotPrice": 0.019,
"timestamp": "2020-11-19T22:04:26.000Z",
"architectures": [
"x86_64"
],
"spotPrice": 0.0103,
"timestamp": "2024-05-15T16:09:23.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-east-2a",
"instanceType": "c5d.large",
"availabilityZone": "us-west-1b",
"instanceType": "c7i-flex.large",
"platform": "Linux/UNIX",
"spotPrice": 0.019,
"timestamp": "2020-11-19T05:58:45.000Z",
"architectures": [
"x86_64"
],
"spotPrice": 0.0108,
"timestamp": "2024-05-16T04:16:55.000Z",
"vCpu": 2,
"memoryGiB": 4
},
{
"availabilityZone": "us-east-2a",
"instanceType": "c5n.large",
"availabilityZone": "us-west-2d",
"instanceType": "m7a.large",
"platform": "Linux/UNIX",
"spotPrice": 0.019,
"timestamp": "2020-11-20T02:27:24.000Z",
"architectures": [
"x86_64"
],
"spotPrice": 0.0117,
"timestamp": "2024-05-16T00:47:33.000Z",
"vCpu": 2,
"memoryGiB": 5.25
"memoryGiB": 8
},
{
"availabilityZone": "us-east-2b",
"instanceType": "c6g.large",
"availabilityZone": "us-west-2b",
"instanceType": "t3a.medium",
"platform": "Linux/UNIX",
"spotPrice": 0.02,
"timestamp": "2020-11-19T13:41:03.000Z",
"architectures": [
"x86_64"
],
"spotPrice": 0.0129,
"timestamp": "2024-05-16T09:02:05.000Z",
"vCpu": 2,
"memoryGiB": 4
}
Expand Down
4 changes: 3 additions & 1 deletion aws-spot-price.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",

// editor
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.rulers": [100],
"editor.tabSize": 2,
"editor.formatOnSave": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build:ec2-info": "ts-node -T scripts/generate-ec2-info.ts",
"build:ec2-types": "ts-node -T scripts/generate-ec2-types.ts",
"build:regions": "ts-node -T scripts/generate-regions.ts",
"build:types": "dts-bundle-generator -o dist/module.d.ts src/module.ts",
"build:types": "dts-bundle-generator -o dist/module.d.ts src/module.ts --external-inlines @aws-sdk/client-ec2",
"build:cli": "yarn esbuild --outdir=./dist --platform=node --format=cjs --bundle --minify --main-fields=module,main --sources-content=false ./src/cli.ts",
"build:module": "yarn esbuild --outdir=./dist --platform=node --format=cjs --bundle --minify --main-fields=module,main --sources-content=false ./src/module.ts",
"build": "yarn build:cli && yarn build:module",
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-spot-prices-mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fetchData = async (region: Region, token?: string): Promise<void> => {
if (results.NextToken) await fetchData(region, results.NextToken);
};

const jsonPath = resolve(__dirname, '../test/spot-prices-mock.json');
const jsonPath = resolve(__dirname, '../test/data/spot-prices-mock.json');

const { argv } = yargs()
.scriptName('generate-spot-prices-mock')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('lib', () => {
beforeAll(async () => {
restoreConsole = mockConsole();
mockDefaultRegionEndpoints();
results = await getGlobalSpotPrices({ architectures: ['arm64'] });
results = await getGlobalSpotPrices();
});

afterAll(() => {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ export const getGlobalSpotPrices = async (options?: {
if (instanceInfo) {
rExtended.vCpu = instanceInfo.vCpu;
rExtended.memoryGiB = instanceInfo.memoryGiB;
rExtended.architectures = instanceInfo.architectures;
} else {
// fetch intance info data from aws
const region = rExtended.availabilityZone.match(/^.+\d/)?.[0];
Expand All @@ -456,14 +457,17 @@ export const getGlobalSpotPrices = async (options?: {
if (
desc[rExtended.instanceType] &&
desc[rExtended.instanceType].vCpu &&
desc[rExtended.instanceType].memoryGiB
desc[rExtended.instanceType].memoryGiB &&
desc[rExtended.instanceType].architectures
) {
ec2Info[rExtended.instanceType] = {
vCpu: desc[rExtended.instanceType].vCpu,
memoryGiB: desc[rExtended.instanceType].memoryGiB,
architectures: desc[rExtended.instanceType].architectures,
};
rExtended.vCpu = desc[rExtended.instanceType].vCpu;
rExtended.memoryGiB = desc[rExtended.instanceType].memoryGiB;
rExtended.architectures = desc[rExtended.instanceType].architectures;
}
}
}
Expand Down
Loading
Loading