Skip to content

Instantly share code, notes, and snippets.

@rantoniuk
Created November 5, 2024 11:56
Show Gist options
  • Save rantoniuk/f9e6c05cb91ae3cfbb20fcdb38f34e19 to your computer and use it in GitHub Desktop.
Save rantoniuk/f9e6c05cb91ae3cfbb20fcdb38f34e19 to your computer and use it in GitHub Desktop.
AWS CLI useful commands

Fetch EC2 Instance Prices for a region

aws --region us-east-1 pricing get-products --service-code AmazonEC2 --filters \
 "Type=TERM_MATCH,Field=capacitystatus,Value=Used" \
 "Type=TERM_MATCH,Field=marketoption,Value=OnDemand" \
 "Type=TERM_MATCH,Field=currentGeneration,Value=Yes" \
 "Type=TERM_MATCH,Field=instanceType,Value=inf1.2xlarge" \
 "Type=TERM_MATCH,Field=location,Value=US West (Oregon)" \
 "Type=TERM_MATCH,Field=operatingSystem,Value=Linux" \
 "Type=TERM_MATCH,Field=marketoption,Value=OnDemand" \
 "Type=TERM_MATCH,Field=servicecode,Value=AmazonEC2" \
 "Type=TERM_MATCH,Field=tenancy,Value=Shared" \
 "Type=TERM_MATCH,Field=operation,Value=RunInstances" \
 | jq -rc '.PriceList[]' | jq -c '[
  .product.attributes.location,
  .product.attributes.instanceType,
  .product.attributes.operatingSystem,
  .product.attributes.memory,
  .product.attributes.physicalProcessor,
  .product.attributes.processorArchitecture,
  .product.attributes.vcpu,
  .terms.OnDemand[].priceDimensions[].description]'       
["US West (Oregon)","inf1.2xlarge","Linux","16 GiB","Intel Xeon Platinum 8275CL (Cascade Lake)","64-bit","8","$0.362 per On Demand Linux inf1.2xlarge Instance Hour"]

In tabular format, add | @tsv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment